mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
refactor(lsp): minor improvements to handling closed documents (#11518)
Ref #10897
This commit is contained in:
parent
091a26104b
commit
c6f4e41529
2 changed files with 22 additions and 7 deletions
|
@ -771,15 +771,21 @@ impl Inner {
|
||||||
async fn did_close(&mut self, params: DidCloseTextDocumentParams) {
|
async fn did_close(&mut self, params: DidCloseTextDocumentParams) {
|
||||||
let mark = self.performance.mark("did_close", Some(¶ms));
|
let mark = self.performance.mark("did_close", Some(¶ms));
|
||||||
if params.text_document.uri.scheme() == "deno" {
|
if params.text_document.uri.scheme() == "deno" {
|
||||||
// we can ignore virtual text documents opening, as they don't need to
|
// we can ignore virtual text documents closing, as they don't need to
|
||||||
// be tracked in memory, as they are static assets that won't change
|
// be tracked in memory, as they are static assets that won't change
|
||||||
// already managed by the language service
|
// already managed by the language service
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let specifier = self.url_map.normalize_url(¶ms.text_document.uri);
|
let specifier = self.url_map.normalize_url(¶ms.text_document.uri);
|
||||||
self.documents.close(&specifier);
|
let is_diagnosable = self.documents.is_diagnosable(&specifier);
|
||||||
|
|
||||||
if self.documents.is_diagnosable(&specifier) {
|
if is_diagnosable {
|
||||||
|
let mut specifiers = self.documents.dependents(&specifier);
|
||||||
|
specifiers.push(specifier.clone());
|
||||||
|
self.diagnostics_server.invalidate(specifiers).await;
|
||||||
|
}
|
||||||
|
self.documents.close(&specifier);
|
||||||
|
if is_diagnosable {
|
||||||
if let Err(err) = self.diagnostics_server.update() {
|
if let Err(err) = self.diagnostics_server.update() {
|
||||||
error!("{}", err);
|
error!("{}", err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,9 @@ delete Object.prototype.__proto__;
|
||||||
/** @type {Map<string, ts.SourceFile>} */
|
/** @type {Map<string, ts.SourceFile>} */
|
||||||
const sourceFileCache = new Map();
|
const sourceFileCache = new Map();
|
||||||
|
|
||||||
|
/** @type {string[]=} */
|
||||||
|
let scriptFileNamesCache;
|
||||||
|
|
||||||
/** @type {Map<string, string>} */
|
/** @type {Map<string, string>} */
|
||||||
const scriptVersionCache = new Map();
|
const scriptVersionCache = new Map();
|
||||||
|
|
||||||
|
@ -370,7 +373,12 @@ delete Object.prototype.__proto__;
|
||||||
},
|
},
|
||||||
getScriptFileNames() {
|
getScriptFileNames() {
|
||||||
debug("host.getScriptFileNames()");
|
debug("host.getScriptFileNames()");
|
||||||
return core.opSync("op_script_names", undefined);
|
// tsc requests the script file names multiple times even though it can't
|
||||||
|
// possibly have changed, so we will memoize it on a per request basis.
|
||||||
|
if (scriptFileNamesCache) {
|
||||||
|
return scriptFileNamesCache;
|
||||||
|
}
|
||||||
|
return scriptFileNamesCache = core.opSync("op_script_names", undefined);
|
||||||
},
|
},
|
||||||
getScriptVersion(specifier) {
|
getScriptVersion(specifier) {
|
||||||
debug(`host.getScriptVersion("${specifier}")`);
|
debug(`host.getScriptVersion("${specifier}")`);
|
||||||
|
@ -378,9 +386,8 @@ delete Object.prototype.__proto__;
|
||||||
if (sourceFile) {
|
if (sourceFile) {
|
||||||
return sourceFile.version ?? "1";
|
return sourceFile.version ?? "1";
|
||||||
}
|
}
|
||||||
// tsc neurotically requests the script version multiple times even though
|
// tsc requests the script version multiple times even though it can't
|
||||||
// it can't possibly have changed, so we will memoize it on a per request
|
// possibly have changed, so we will memoize it on a per request basis.
|
||||||
// basis.
|
|
||||||
if (scriptVersionCache.has(specifier)) {
|
if (scriptVersionCache.has(specifier)) {
|
||||||
return scriptVersionCache.get(specifier);
|
return scriptVersionCache.get(specifier);
|
||||||
}
|
}
|
||||||
|
@ -543,6 +550,8 @@ delete Object.prototype.__proto__;
|
||||||
*/
|
*/
|
||||||
function serverRequest({ id, ...request }) {
|
function serverRequest({ id, ...request }) {
|
||||||
debug(`serverRequest()`, { id, ...request });
|
debug(`serverRequest()`, { id, ...request });
|
||||||
|
// reset all memoized source files names
|
||||||
|
scriptFileNamesCache = undefined;
|
||||||
// evict all memoized source file versions
|
// evict all memoized source file versions
|
||||||
scriptVersionCache.clear();
|
scriptVersionCache.clear();
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
|
|
Loading…
Reference in a new issue