Skip to content

Commit

Permalink
Support custom dfx canister principals (#284)
Browse files Browse the repository at this point in the history
* Support 'type: custom' dfx canisters

* Add virtual Candid files in LSP directory

* 0.16.4
  • Loading branch information
rvanasa committed Jun 11, 2024
1 parent d03e364 commit 2192518
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 6 additions & 0 deletions src/server/dfx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { dirname } from 'path';
interface DfxCanister {
type?: string;
main?: string;
remote?: {
candid?: string;
id?: {
local?: string;
};
};
}

interface DfxConfig {
Expand Down
27 changes: 27 additions & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2192518

Please sign in to comment.