diff --git a/package-lock.json b/package-lock.json index ebcd2ac..4ad019f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-motoko", - "version": "0.16.3", + "version": "0.16.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-motoko", - "version": "0.16.3", + "version": "0.16.4", "hasInstallScript": true, "dependencies": { "@wasmer/wasi": "1.2.2", diff --git a/package.json b/package.json index db68113..708a5c9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-motoko", "displayName": "Motoko", "description": "Motoko language support", - "version": "0.16.3", + "version": "0.16.4", "publisher": "dfinity-foundation", "repository": "https://github.com/dfinity/vscode-motoko", "engines": { diff --git a/src/server/dfx.ts b/src/server/dfx.ts index 8cc8142..954cec4 100644 --- a/src/server/dfx.ts +++ b/src/server/dfx.ts @@ -4,6 +4,12 @@ import { dirname } from 'path'; interface DfxCanister { type?: string; main?: string; + remote?: { + candid?: string; + id?: { + local?: string; + }; + }; } interface DfxConfig { diff --git a/src/server/server.ts b/src/server/server.ts index 3c85076..aac7968 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -438,7 +438,34 @@ function notifyDfxChange() { }, ); } + Object.entries(dfxConfig.canisters).forEach( + ([name, canister]) => { + if (!aliases.hasOwnProperty(name)) { + const id = canister.remote?.id?.local; + if (id) { + aliases[name] = id; + const candidPath = + canister.remote?.candid; + if (candidPath) { + // Add Candid as virtual file in LSP directory + const candid = readFileSync( + resolve(projectDir, candidPath), + 'utf8', + ); + writeVirtual( + resolveVirtualPath( + candidUri, + `${id}.did`, + ), + candid, + ); + } + } + } + }, + ); allContexts().forEach(({ motoko }) => { + console.log('Actor aliases:', aliases); motoko.setAliases( resolveVirtualPath(candidUri), aliases,