Skip to content

Fix extension crash when renaming a file. #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2022
Merged
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
37 changes: 1 addition & 36 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,6 @@ if (process.argv.includes("--stdio")) {
function hover(msg: p.RequestMessage) {
let params = msg.params as p.HoverParams;
let filePath = fileURLToPath(params.textDocument.uri);
let extension = path.extname(params.textDocument.uri);
if (extension !== c.resExt && extension !== c.resiExt) {
// Can be called on renamed extension after rename
return {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result: null,
};
}
let code = getOpenedFileContent(params.textDocument.uri);
let tmpname = utils.createFileInTempDir();
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
Expand Down Expand Up @@ -408,14 +399,6 @@ function documentSymbol(msg: p.RequestMessage) {
let params = msg.params as p.DocumentSymbolParams;
let filePath = fileURLToPath(params.textDocument.uri);
let extension = path.extname(params.textDocument.uri);
if (extension !== c.resExt && extension !== c.resiExt) {
// Can be called on renamed extension after rename
return {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result: null,
};
}
let code = getOpenedFileContent(params.textDocument.uri);
let tmpname = utils.createFileInTempDir(extension);
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
Expand All @@ -434,14 +417,6 @@ function semanticTokens(msg: p.RequestMessage) {
let params = msg.params as p.SemanticTokensParams;
let filePath = fileURLToPath(params.textDocument.uri);
let extension = path.extname(params.textDocument.uri);
if (extension !== c.resExt && extension !== c.resiExt) {
// Can be called on renamed extension after rename
return {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result: null,
};
}
let code = getOpenedFileContent(params.textDocument.uri);
let tmpname = utils.createFileInTempDir(extension);
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
Expand All @@ -460,14 +435,6 @@ function completion(msg: p.RequestMessage) {
let params = msg.params as p.ReferenceParams;
let filePath = fileURLToPath(params.textDocument.uri);
let extension = path.extname(params.textDocument.uri);
if (extension !== c.resExt && extension !== c.resiExt) {
// Can be called on renamed extension after rename
return {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result: null,
};
}
let code = getOpenedFileContent(params.textDocument.uri);
let tmpname = utils.createFileInTempDir();
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
Expand Down Expand Up @@ -777,9 +744,7 @@ function onMessage(msg: m.Message) {
} else if (msg.method === DidOpenTextDocumentNotification.method) {
let params = msg.params as p.DidOpenTextDocumentParams;
let extName = path.extname(params.textDocument.uri);
if (extName === c.resExt || extName === c.resiExt) {
openedFile(params.textDocument.uri, params.textDocument.text);
}
openedFile(params.textDocument.uri, params.textDocument.text);
} else if (msg.method === DidChangeTextDocumentNotification.method) {
let params = msg.params as p.DidChangeTextDocumentParams;
let extName = path.extname(params.textDocument.uri);
Expand Down