mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(lsp): scope attribution for lazily loaded assets (#26699)
This commit is contained in:
parent
f6a0ba7609
commit
7fc74b2b23
2 changed files with 50 additions and 6 deletions
|
@ -801,7 +801,11 @@ delete Object.prototype.__proto__;
|
||||||
if (logDebug) {
|
if (logDebug) {
|
||||||
debug(`host.getScriptSnapshot("${specifier}")`);
|
debug(`host.getScriptSnapshot("${specifier}")`);
|
||||||
}
|
}
|
||||||
const sourceFile = sourceFileCache.get(specifier);
|
if (specifier.startsWith(ASSETS_URL_PREFIX)) {
|
||||||
|
const sourceFile = this.getSourceFile(
|
||||||
|
specifier,
|
||||||
|
ts.ScriptTarget.ESNext,
|
||||||
|
);
|
||||||
if (sourceFile) {
|
if (sourceFile) {
|
||||||
if (!assetScopes.has(specifier)) {
|
if (!assetScopes.has(specifier)) {
|
||||||
assetScopes.set(specifier, lastRequestScope);
|
assetScopes.set(specifier, lastRequestScope);
|
||||||
|
@ -809,6 +813,7 @@ delete Object.prototype.__proto__;
|
||||||
// This case only occurs for assets.
|
// This case only occurs for assets.
|
||||||
return ts.ScriptSnapshot.fromString(sourceFile.text);
|
return ts.ScriptSnapshot.fromString(sourceFile.text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let sourceText = sourceTextCache.get(specifier);
|
let sourceText = sourceTextCache.get(specifier);
|
||||||
if (sourceText == undefined) {
|
if (sourceText == undefined) {
|
||||||
/** @type {{ data: string, version: string, isCjs: boolean }} */
|
/** @type {{ data: string, version: string, isCjs: boolean }} */
|
||||||
|
|
|
@ -6396,6 +6396,45 @@ fn lsp_cache_on_save() {
|
||||||
client.shutdown();
|
client.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/denoland/deno/issues/25999.
|
||||||
|
#[test]
|
||||||
|
fn lsp_asset_document_dom_code_action() {
|
||||||
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
||||||
|
let temp_dir = context.temp_dir();
|
||||||
|
temp_dir.write(
|
||||||
|
"deno.json",
|
||||||
|
json!({
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["deno.window", "dom"],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
let mut client = context.new_lsp_command().build();
|
||||||
|
client.initialize_default();
|
||||||
|
client.did_open(json!({
|
||||||
|
"textDocument": {
|
||||||
|
"uri": temp_dir.url().join("file.ts").unwrap(),
|
||||||
|
"languageId": "typescript",
|
||||||
|
"version": 1,
|
||||||
|
"text": r#""#,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
let res = client.write_request(
|
||||||
|
"textDocument/codeAction",
|
||||||
|
json!({
|
||||||
|
"textDocument": { "uri": "asset:///lib.dom.d.ts" },
|
||||||
|
"range": {
|
||||||
|
"start": { "line": 0, "character": 0 },
|
||||||
|
"end": { "line": 0, "character": 0 },
|
||||||
|
},
|
||||||
|
"context": { "diagnostics": [], "only": ["quickfix"] },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assert_eq!(res, json!(null));
|
||||||
|
client.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/denoland/deno/issues/22122.
|
// Regression test for https://github.com/denoland/deno/issues/22122.
|
||||||
#[test]
|
#[test]
|
||||||
fn lsp_cache_then_definition() {
|
fn lsp_cache_then_definition() {
|
||||||
|
|
Loading…
Reference in a new issue