From 0843898ca4ac74c1acb88204cac5a14a07a23be6 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 6 Aug 2026 22:54:22 -0300 Subject: [PATCH 1/2] Fix empty completion In https://github.com/rescript-lang/rescript/pull/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 --- server/src/server.ts | 18 +++++++----------- server/src/utils.ts | 4 ++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index f4829dd0e..23ccd9602 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -623,7 +623,7 @@ async function hover(msg: p.RequestMessage) { params.textDocument.uri as utils.FileURI, ); let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI); - let tmpname = utils.createFileInTempDir(); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let response = await utils.runAnalysisCommand( filePath, @@ -699,7 +699,7 @@ async function signatureHelp(msg: p.RequestMessage) { params.textDocument.uri as utils.FileURI, ); let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI); - let tmpname = utils.createFileInTempDir(); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let response = await utils.runAnalysisCommand( filePath, @@ -871,9 +871,8 @@ async function documentSymbol(msg: p.RequestMessage) { let filePath = utils.uriToNormalizedPath( params.textDocument.uri as utils.FileURI, ); - let extension = path.extname(params.textDocument.uri); let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI); - let tmpname = utils.createFileInTempDir(extension); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let response = await utils.runAnalysisCommand( filePath, @@ -909,9 +908,8 @@ async function semanticTokens(msg: p.RequestMessage) { let filePath = utils.uriToNormalizedPath( params.textDocument.uri as utils.FileURI, ); - let extension = path.extname(params.textDocument.uri); let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI); - let tmpname = utils.createFileInTempDir(extension); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let response = await utils.runAnalysisCommand( filePath, @@ -930,7 +928,7 @@ async function completion(msg: p.RequestMessage) { params.textDocument.uri as utils.FileURI, ); let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI); - let tmpname = utils.createFileInTempDir(); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let response = await utils.runAnalysisCommand( filePath, @@ -978,8 +976,7 @@ async function codeAction(msg: p.RequestMessage): Promise { params.textDocument.uri as utils.FileURI, ); let code = getOpenedFileContent(params.textDocument.uri as utils.FileURI); - let extension = path.extname(params.textDocument.uri); - let tmpname = utils.createFileInTempDir(extension); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); // Check local code actions coming from the diagnostics, or from incremental compilation. let localResults: v.CodeAction[] = []; @@ -1102,8 +1099,7 @@ let updateDiagnosticSyntax = async ( return; } let filePath = utils.uriToNormalizedPath(fileUri); - let extension = path.extname(filePath); - let tmpname = utils.createFileInTempDir(extension); + let tmpname = utils.createFileInTempDir(utils.getExtension(filePath)); fs.writeFileSync(tmpname, fileContent, { encoding: "utf-8" }); // We need to account for any existing diagnostics from the compiler for this diff --git a/server/src/utils.ts b/server/src/utils.ts index e249f3398..e4c34e256 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -82,6 +82,10 @@ export function uriToNormalizedPath(uri: FileURI): NormalizedPath { let tempFilePrefix = "rescript_format_file_" + process.pid + "_"; let tempFileId = 0; +export function getExtension(filePath: NormalizedPath): string { + return path.extname(filePath); +} + export let createFileInTempDir = (extension = ""): NormalizedPath => { let tempFileName = tempFilePrefix + tempFileId + extension; tempFileId = tempFileId + 1; From f20e57d001e929447735006b1da38f2db17d6c65 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 8 Aug 2026 15:38:03 -0300 Subject: [PATCH 2/2] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 898393cbc..296ef4575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Potential race condition in incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/1167 - Fix extension crash triggered by incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/1169 - Fix file watchers on Windows when using WSL. https://github.com/rescript-lang/rescript-vscode/pull/1178 +- Fix empty completion in rescript@13.0.0-alpha.5. https://github.com/rescript-lang/rescript-vscode/pull/1188 #### :nail_care: Polish