Skip to content

Commit 9ff287b

Browse files
committed
Fix extension crash when renaming a file.
More robust solution where the file cache is set also for files with extension not `.res` or `.resi`. In case of rename e.g. from `.res` to `.rex` an opened file notification is sent for the `.rex` file and a crash happens when trying to get the current file content. After this change, the file content array is set also for the .rex` file, preventing the crash. Fixes #392
1 parent e9c21a0 commit 9ff287b

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

server/src/server.ts

+1-36
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,6 @@ if (process.argv.includes("--stdio")) {
271271
function hover(msg: p.RequestMessage) {
272272
let params = msg.params as p.HoverParams;
273273
let filePath = fileURLToPath(params.textDocument.uri);
274-
let extension = path.extname(params.textDocument.uri);
275-
if (extension !== c.resExt && extension !== c.resiExt) {
276-
// Can be called on renamed extension after rename
277-
return {
278-
jsonrpc: c.jsonrpcVersion,
279-
id: msg.id,
280-
result: null,
281-
};
282-
}
283274
let code = getOpenedFileContent(params.textDocument.uri);
284275
let tmpname = utils.createFileInTempDir();
285276
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
@@ -408,14 +399,6 @@ function documentSymbol(msg: p.RequestMessage) {
408399
let params = msg.params as p.DocumentSymbolParams;
409400
let filePath = fileURLToPath(params.textDocument.uri);
410401
let extension = path.extname(params.textDocument.uri);
411-
if (extension !== c.resExt && extension !== c.resiExt) {
412-
// Can be called on renamed extension after rename
413-
return {
414-
jsonrpc: c.jsonrpcVersion,
415-
id: msg.id,
416-
result: null,
417-
};
418-
}
419402
let code = getOpenedFileContent(params.textDocument.uri);
420403
let tmpname = utils.createFileInTempDir(extension);
421404
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
@@ -434,14 +417,6 @@ function semanticTokens(msg: p.RequestMessage) {
434417
let params = msg.params as p.SemanticTokensParams;
435418
let filePath = fileURLToPath(params.textDocument.uri);
436419
let extension = path.extname(params.textDocument.uri);
437-
if (extension !== c.resExt && extension !== c.resiExt) {
438-
// Can be called on renamed extension after rename
439-
return {
440-
jsonrpc: c.jsonrpcVersion,
441-
id: msg.id,
442-
result: null,
443-
};
444-
}
445420
let code = getOpenedFileContent(params.textDocument.uri);
446421
let tmpname = utils.createFileInTempDir(extension);
447422
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
@@ -460,14 +435,6 @@ function completion(msg: p.RequestMessage) {
460435
let params = msg.params as p.ReferenceParams;
461436
let filePath = fileURLToPath(params.textDocument.uri);
462437
let extension = path.extname(params.textDocument.uri);
463-
if (extension !== c.resExt && extension !== c.resiExt) {
464-
// Can be called on renamed extension after rename
465-
return {
466-
jsonrpc: c.jsonrpcVersion,
467-
id: msg.id,
468-
result: null,
469-
};
470-
}
471438
let code = getOpenedFileContent(params.textDocument.uri);
472439
let tmpname = utils.createFileInTempDir();
473440
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
@@ -777,9 +744,7 @@ function onMessage(msg: m.Message) {
777744
} else if (msg.method === DidOpenTextDocumentNotification.method) {
778745
let params = msg.params as p.DidOpenTextDocumentParams;
779746
let extName = path.extname(params.textDocument.uri);
780-
if (extName === c.resExt || extName === c.resiExt) {
781-
openedFile(params.textDocument.uri, params.textDocument.text);
782-
}
747+
openedFile(params.textDocument.uri, params.textDocument.text);
783748
} else if (msg.method === DidChangeTextDocumentNotification.method) {
784749
let params = msg.params as p.DidChangeTextDocumentParams;
785750
let extName = path.extname(params.textDocument.uri);

0 commit comments

Comments
 (0)