Skip to content

[WIP] Completion revamping #1084

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
],
"default": null,
"description": "Path to the directory where platform-specific ReScript binaries are. You can use it if you haven't or don't want to use the installed ReScript from node_modules in your project."
},
"rescript.settings.newCompletion": {
"type": "boolean",
"default": false,
"description": "(experimental) Enable new completion engine"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface extensionConfiguration {
codeLens?: boolean;
binaryPath?: string | null;
platformPath?: string | null;
newCompletion?: boolean;
signatureHelp?: {
enabled?: boolean;
forConstructorPayloads?: boolean;
Expand Down Expand Up @@ -39,6 +40,7 @@ let config: { extensionConfiguration: extensionConfiguration } = {
codeLens: false,
binaryPath: null,
platformPath: null,
newCompletion: false,
signatureHelp: {
enabled: true,
forConstructorPayloads: true,
Expand Down
6 changes: 4 additions & 2 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function removeAnsiCodes(s: string): string {
const ansiEscape = /\x1B[@-_][0-?]*[ -/]*[@-~]/g;
return s.replace(ansiEscape, "");
}
function triggerIncrementalCompilationOfFile(
export function triggerIncrementalCompilationOfFile(
filePath: string,
fileContent: string,
send: send,
Expand Down Expand Up @@ -469,9 +469,10 @@ function triggerIncrementalCompilationOfFile(
entry.killCompilationListeners = [];
}
const triggerToken = performance.now();
// TODO: Can we remove this timeout? Don't remember why it was added...
const timeout = setTimeout(() => {
compileContents(entry, fileContent, send, onCompilationFinished);
}, 20);
}, 0);

if (entry.compilation != null) {
entry.compilation.timeout = timeout;
Expand Down Expand Up @@ -727,6 +728,7 @@ async function compileContents(
}
}

// TODO(compilation-revamp) make sure we don't unecessarily trigger incremental compilations
export function handleUpdateOpenedFile(
filePath: string,
fileContent: string,
Expand Down
13 changes: 11 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,22 @@ function semanticTokens(msg: p.RequestMessage) {
return response;
}

function completion(msg: p.RequestMessage) {
async function completion(msg: p.RequestMessage) {
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
let params = msg.params as p.ReferenceParams;
let filePath = fileURLToPath(params.textDocument.uri);
let code = getOpenedFileContent(params.textDocument.uri);
let tmpname = utils.createFileInTempDir();
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });

if (config.extensionConfiguration.newCompletion) {
await new Promise<void>((resolve) => {
ic.triggerIncrementalCompilationOfFile(filePath, code, send, () => {
resolve();
});
});
}

let response = utils.runAnalysisCommand(
filePath,
[
Expand Down Expand Up @@ -1235,7 +1244,7 @@ function onMessage(msg: p.Message) {
} else if (msg.method === p.DocumentSymbolRequest.method) {
send(documentSymbol(msg));
} else if (msg.method === p.CompletionRequest.method) {
send(completion(msg));
completion(msg).then(send);
} else if (msg.method === p.CompletionResolveRequest.method) {
send(completionResolve(msg));
} else if (msg.method === p.SemanticTokensRequest.method) {
Expand Down
4 changes: 4 additions & 0 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export let runAnalysisAfterSanityCheck = (
config.extensionConfiguration.cache?.projectConfig?.enable === true
? "true"
: undefined,
RESCRIPT_NEW_ANALYSIS_ENGINE:
config.extensionConfiguration.newCompletion === true
? "true"
: undefined,
},
};

Expand Down