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 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;