I'm coding a vscode extension following the guide and I came accross an import problem in my server.ts file. Here is the file tree:
📦test
┣ 📂client
┃ ┣ 📂out
┃ ┣ 📂src
┃ ┃ ┗ 📜index.ts
┃ ┣ 📜package-lock.json
┃ ┣ 📜package.json
┃ ┗ 📜tsconfig.json
┣ 📂server
┃ ┣ 📂out
┃ ┣ 📂src
┃ ┃ ┣ 📜completions.ts
┃ ┃ ┣ 📜parser.ts
┃ ┃ ┗ 📜server.ts
┃ ┣ 📜package-lock.json
┃ ┣ 📜package.json
┃ ┣ 📜tsconfig.json
┃ ┗ 📜yarn.lock
┣ 📜package.json
┗ 📜tsconfig.json
Which is the same structrure as the extension sample provided by Microsoft.
However, in server.ts, I'm trying to import some elements from the vscode module:
//server.ts
import { workspace as Workspace } from 'vscode';
let sm_home: string = Workspace.getConfiguration("sourcepawnLanguageServer").get("sourcemod_home");
...
and in my package.json, I have:
"dependencies": {
"@types/glob": "^5.0.30",
"@types/uuid": "^3.4.0",
"@types/vscode": "^1.14.0",
"glob": "^7.1.2",
"uuid": "^3.1.0",
"vscode-languageserver": "^7.0.0",
"vscode-languageserver-textdocument": "^1.0.1",
"vscode-test": "1.5.1",
"vscode-uri": "^3.0.2"
},
The whole project compiles fine, but when I start the extension, I get the following error:
Error: Cannot find module 'vscode'
Require stack:
- c:\Users\Charles\CloudStation\Documents\Perso\Dev\sourcepawn-vscode\server\out\server.js
at Function._resolveFilename (internal/modules/cjs/loader.js:1019:15)
at internal/modules/cjs/loader.js:895:27
at Function._load (electron/js2c/asar_bundle.js:5:12738)
at Module.require (internal/modules/cjs/loader.js:1079:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (c:\Users\Charles\CloudStation\Documents\Perso\Dev\sourcepawn-vscode\server\out\server.js:5:18)
at Module._compile (internal/modules/cjs/loader.js:1199:30)
at Object..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1039:32)
at internal/modules/cjs/loader.js:932:14 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'c:\\Users\\Charles\\CloudStation\\Documents\\Perso\\Dev\\sourcepawn-vscode\\server\\out\\server.js'
]
}
And the error goes away if I remove the import and the line using the import in the server.ts file.
This import works fine in index.ts` Could this be due to the fact that server.tsis called inside ofindex.ts` ?
import { ExtensionContext, workspace as Workspace, window, commands } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
import * as glob from 'glob';
import * as path from 'path';
export const sm_home: string = 'Workspace.getConfiguration("sourcepawnLanguageServer").get("sourcemod_home")';
export function activate(context: ExtensionContext) {
let serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
...
This doesn't seem to bother the C/C++ extension.
Thanks in advance for the help!