Skip to content

Commit e8f8d07

Browse files
authored
Fix empty completion (#1188)
In rescript-lang/rescript#8426, a refactoring was implemented to read files from a string instead of from the disk. The `Files.classify_source_file` function checks whether a file is `Res`, `Resi`, or `Other`. Since `server.ts` creates a file without an extension in the temporary directory, `Files.classify_source_file` returns `Other`, resulting in no output for `textDocument/completion`. Close #1187
1 parent 29e1029 commit e8f8d07

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Potential race condition in incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/1167
2222
- Fix extension crash triggered by incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/1169
2323
- Fix file watchers on Windows when using WSL. https://github.com/rescript-lang/rescript-vscode/pull/1178
24+
- Fix empty completion in rescript@13.0.0-alpha.5. https://github.com/rescript-lang/rescript-vscode/pull/1188
2425

2526
#### :nail_care: Polish
2627

‎server/src/server.ts‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ async function hover(msg: p.RequestMessage) {
623623
params.textDocument.uri as utils.FileURI,
624624
);
625625
let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI);
626-
let tmpname = utils.createFileInTempDir();
626+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
627627
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
628628
let response = await utils.runAnalysisCommand(
629629
filePath,
@@ -699,7 +699,7 @@ async function signatureHelp(msg: p.RequestMessage) {
699699
params.textDocument.uri as utils.FileURI,
700700
);
701701
let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI);
702-
let tmpname = utils.createFileInTempDir();
702+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
703703
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
704704
let response = await utils.runAnalysisCommand(
705705
filePath,
@@ -871,9 +871,8 @@ async function documentSymbol(msg: p.RequestMessage) {
871871
let filePath = utils.uriToNormalizedPath(
872872
params.textDocument.uri as utils.FileURI,
873873
);
874-
let extension = path.extname(params.textDocument.uri);
875874
let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI);
876-
let tmpname = utils.createFileInTempDir(extension);
875+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
877876
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
878877
let response = await utils.runAnalysisCommand(
879878
filePath,
@@ -909,9 +908,8 @@ async function semanticTokens(msg: p.RequestMessage) {
909908
let filePath = utils.uriToNormalizedPath(
910909
params.textDocument.uri as utils.FileURI,
911910
);
912-
let extension = path.extname(params.textDocument.uri);
913911
let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI);
914-
let tmpname = utils.createFileInTempDir(extension);
912+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
915913
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
916914
let response = await utils.runAnalysisCommand(
917915
filePath,
@@ -930,7 +928,7 @@ async function completion(msg: p.RequestMessage) {
930928
params.textDocument.uri as utils.FileURI,
931929
);
932930
let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI);
933-
let tmpname = utils.createFileInTempDir();
931+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
934932
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
935933
let response = await utils.runAnalysisCommand(
936934
filePath,
@@ -978,8 +976,7 @@ async function codeAction(msg: p.RequestMessage): Promise<p.ResponseMessage> {
978976
params.textDocument.uri as utils.FileURI,
979977
);
980978
let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI);
981-
let extension = path.extname(params.textDocument.uri);
982-
let tmpname = utils.createFileInTempDir(extension);
979+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
983980

984981
// Check local code actions coming from the diagnostics, or from incremental compilation.
985982
let localResults: v.CodeAction[] = [];
@@ -1102,8 +1099,7 @@ let updateDiagnosticSyntax = async (
11021099
return;
11031100
}
11041101
let filePath = utils.uriToNormalizedPath(fileUri);
1105-
let extension = path.extname(filePath);
1106-
let tmpname = utils.createFileInTempDir(extension);
1102+
let tmpname = utils.createFileInTempDir(utils.getExtension(filePath));
11071103
fs.writeFileSync(tmpname, fileContent, { encoding: "utf-8" });
11081104

11091105
// We need to account for any existing diagnostics from the compiler for this

‎server/src/utils.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export function uriToNormalizedPath(uri: FileURI): NormalizedPath {
8282
let tempFilePrefix = "rescript_format_file_" + process.pid + "_";
8383
let tempFileId = 0;
8484

85+
export function getExtension(filePath: NormalizedPath): string {
86+
return path.extname(filePath);
87+
}
88+
8589
export let createFileInTempDir = (extension = ""): NormalizedPath => {
8690
let tempFileName = tempFilePrefix + tempFileId + extension;
8791
tempFileId = tempFileId + 1;

0 commit comments

Comments
 (0)