Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom dfx canister principals #284

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading