Skip to content

Commit

Permalink
Improve type checking UX (#239)
Browse files Browse the repository at this point in the history
* Adjust 'processQueue()' logic

* Optimize main file type checking

* Increase main file type checking debounce

* Fix type checker sometimes using outdated file content

* 0.13.11

* Refactor for clarity

* Cancel checking workspace on file change
  • Loading branch information
rvanasa authored Aug 22, 2023
1 parent 83f9903 commit c9be1f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 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.13.10",
"version": "0.13.11",
"publisher": "dfinity-foundation",
"repository": "https://github.com/dfinity/vscode-motoko",
"engines": {
Expand Down
19 changes: 7 additions & 12 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ const checkQueue: string[] = [];
let checkTimeout: ReturnType<typeof setTimeout>;
function processQueue() {
clearTimeout(checkTimeout);
clearTimeout(checkWorkspaceTimeout);
checkTimeout = setTimeout(() => {
const uri = checkQueue.shift();
if (checkQueue.length) {
Expand Down Expand Up @@ -681,11 +682,6 @@ function checkWorkspace() {
}, 1000);
}

function validate(uri: string | TextDocument) {
notify(uri);
scheduleCheck(uri);
}

/**
* Registers or updates the URI or document in the compiler's virtual file system.
*/
Expand Down Expand Up @@ -1411,20 +1407,19 @@ async function sendDiagnostics(params: {
let validatingTimeout: ReturnType<typeof setTimeout>;
let validatingUri: string | undefined;
documents.onDidChangeContent((event) => {
if (packageConfigError) {
// notifyPackageConfigChange(true);
}
const document = event.document;
const { uri } = document;
if (uri === validatingUri) {
clearTimeout(validatingTimeout);
}
notify(document);
validatingUri = uri;
validatingTimeout = setTimeout(() => {
validate(document);
const { astResolver } = getContext(uri);
astResolver.update(uri, true); /// TODO: also use for type checking?
}, 100);
notify(document);
scheduleCheck(document);
// const { astResolver } = getContext(uri);
// astResolver.update(uri, true); // TODO: also use for type checking?
}, 500);
});

documents.onDidOpen((event) => scheduleCheck(event.document.uri));
Expand Down

0 comments on commit c9be1f4

Please sign in to comment.