Skip to content
Open
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
18 changes: 7 additions & 11 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -978,8 +976,7 @@ async function codeAction(msg: p.RequestMessage): Promise<p.ResponseMessage> {
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[] = [];
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading