1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

refactor(lsp): improve test client initialization (#18015)

This commit is contained in:
David Sherret 2023-03-08 18:15:20 -05:00 committed by GitHub
parent f2e5e01832
commit 25d98ca289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
92 changed files with 3944 additions and 5796 deletions

1
Cargo.lock generated
View file

@ -4953,6 +4953,7 @@ dependencies = [
"futures",
"hyper",
"lazy_static",
"lsp-types",
"once_cell",
"os_pipe",
"parking_lot 0.12.1",

View file

@ -95,6 +95,7 @@ hyper = "0.14.18"
indexmap = { version = "1.9.2", features = ["serde"] }
libc = "0.2.126"
log = "=0.4.17"
lsp-types = "=0.93.2" # used by tower-lsp and "proposed" feature is unstable in patch releases
lzzzz = "1.0"
notify = "=5.0.0"
once_cell = "1.17.1"
@ -122,6 +123,7 @@ tokio = { version = "=1.25.0", features = ["full"] }
tokio-rustls = "0.23.3"
tokio-tungstenite = "0.16.1"
tokio-util = "0.7.4"
tower-lsp = { version = "=0.17.0", features = ["proposed"] }
url = { version = "2.3.1", features = ["serde", "expose_internals"] }
uuid = { version = "1.3.0", features = ["v4"] }
zstd = "=0.11.2"

View file

@ -80,7 +80,7 @@ indexmap.workspace = true
jsonc-parser = { version = "=0.21.0", features = ["serde"] }
libc.workspace = true
log = { workspace = true, features = ["serde"] }
lsp-types = "=0.93.2" # used by tower-lsp and "proposed" feature is unstable in patch releases
lsp-types.workspace = true
lzzzz = '1.0'
mitata = "=0.0.7"
monch = "=0.4.1"
@ -104,7 +104,7 @@ text_lines = "=0.6.0"
thiserror = "=1.0.38"
tokio.workspace = true
tokio-util.workspace = true
tower-lsp = { version = "=0.17.0", features = ["proposed"] }
tower-lsp.workspace = true
twox-hash = "=1.6.3"
typed-arena = "=2.0.1"
uuid = { workspace = true, features = ["serde"] }

View file

@ -9,15 +9,13 @@ use deno_core::url::Url;
use std::collections::HashMap;
use std::path::Path;
use std::time::Duration;
use test_util::lsp::LspClient;
use test_util::lsp::LspClientBuilder;
use test_util::lsp::LspResponseError;
use tower_lsp::lsp_types as lsp;
static FIXTURE_CODE_LENS_TS: &str = include_str!("testdata/code_lens.ts");
static FIXTURE_DB_TS: &str = include_str!("testdata/db.ts");
static FIXTURE_DB_MESSAGES: &[u8] = include_bytes!("testdata/db_messages.json");
static FIXTURE_INIT_JSON: &[u8] =
include_bytes!("testdata/initialize_params.json");
#[derive(Debug, Deserialize)]
enum FixtureType {
@ -44,14 +42,8 @@ struct FixtureMessage {
/// the end of the document and does a level of hovering and gets quick fix
/// code actions.
fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
let (_, response_error): (Option<Value>, Option<LspResponseError>) =
client.write_request("initialize", params)?;
assert!(response_error.is_none());
client.write_notification("initialized", json!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();
client.write_notification(
"textDocument/didOpen",
@ -125,13 +117,8 @@ fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
}
fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
let (_, maybe_err) =
client.write_request::<_, _, Value>("initialize", params)?;
assert!(maybe_err.is_none());
client.write_notification("initialized", json!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();
client.write_notification(
"textDocument/didOpen",
@ -189,13 +176,8 @@ fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
}
fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
let (_, maybe_err) =
client.write_request::<_, _, Value>("initialize", params)?;
assert!(maybe_err.is_none());
client.write_notification("initialized", json!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();
for i in 0..10 {
client.write_notification(
@ -285,14 +267,8 @@ fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {
/// A test that starts up the LSP, opens a single line document, and exits.
fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
let (_, response_error) =
client.write_request::<_, _, Value>("initialize", params)?;
assert!(response_error.is_none());
client.write_notification("initialized", json!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();
client.write_notification(
"textDocument/didOpen",

View file

@ -3,25 +3,16 @@
use deno_bench_util::bencher::benchmark_group;
use deno_bench_util::bencher::benchmark_main;
use deno_bench_util::bencher::Bencher;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use test_util::lsp::LspClient;
use test_util::lsp::LspClientBuilder;
// Intended to match the benchmark in quick-lint-js
// https://github.com/quick-lint/quick-lint-js/blob/35207e6616267c6c81be63f47ce97ec2452d60df/benchmark/benchmark-lsp/lsp-benchmarks.cpp#L223-L268
fn incremental_change_wait(bench: &mut Bencher) {
let deno_exe = test_util::deno_exe_path();
let mut client = LspClient::new(&deno_exe, false).unwrap();
static FIXTURE_INIT_JSON: &[u8] =
include_bytes!("testdata/initialize_params.json");
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON).unwrap();
let (_, maybe_err) = client
.write_request::<_, _, Value>("initialize", params)
.unwrap();
assert!(maybe_err.is_none());
client.write_notification("initialized", json!({})).unwrap();
let mut client = LspClientBuilder::new().build();
client.initialize_default();
client
.write_notification(

File diff suppressed because it is too large Load diff

View file

@ -1,2 +0,0 @@
// deno-lint-ignore-file no-var
declare var a: string;

View file

@ -1,2 +0,0 @@
// deno-lint-ignore-file no-var
declare var b: string;

View file

@ -1,39 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 1,
"character": 5
},
"end": {
"line": 1,
"character": 12
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 5
},
"end": {
"line": 1,
"character": 12
}
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'message' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,92 +0,0 @@
[
{
"title": "Disable prefer-const for this line",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": { "line": 1, "character": 5 },
"end": { "line": 1, "character": 12 }
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'message' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": { "line": 1, "character": 0 },
"end": { "line": 1, "character": 0 }
},
"newText": "// deno-lint-ignore prefer-const\n"
}
]
}
}
},
{
"title": "Disable prefer-const for the entire file",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": { "line": 1, "character": 5 },
"end": { "line": 1, "character": 12 }
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'message' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 }
},
"newText": "// deno-lint-ignore-file prefer-const\n"
}
]
}
}
},
{
"title": "Ignore lint errors for the entire file",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": { "line": 1, "character": 5 },
"end": { "line": 1, "character": 12 }
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'message' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 }
},
"newText": "// deno-lint-ignore-file\n"
}
]
}
}
}
]

View file

@ -1,39 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 7
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 7
}
},
"severity": 1,
"code": 1308,
"source": "deno-ts",
"message": "'await' expressions are only allowed within async functions and at the top levels of modules.",
"relatedInformation": []
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,41 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 49
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 49
}
},
"severity": 1,
"code": "no-cache",
"source": "deno",
"message": "Unable to load the remote module: \"https://deno.land/x/a/mod.ts\".",
"data": {
"specifier": "https://deno.land/x/a/mod.ts"
}
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,38 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 441,
"character": 33
},
"end": {
"line": 441,
"character": 42
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 441,
"character": 33
},
"end": {
"line": 441,
"character": 42
}
},
"severity": 1,
"code": 7031,
"source": "deno-ts",
"message": "Binding element 'debugFlag' implicitly has an 'any' type."
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,38 +0,0 @@
{
"textDocument": {
"uri": "file:///a/a.ts"
},
"range": {
"start": {
"line": 0,
"character": 14
},
"end": {
"line": 0,
"character": 27
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 14
},
"end": {
"line": 0,
"character": 27
}
},
"severity": 1,
"code": "no-assert-type",
"source": "deno",
"message": "The module is a JSON module and not being imported with an import assertion. Consider adding `assert { type: \"json\" }` to the import statement."
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,54 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file00.ts"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 6,
"character": 0
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 50
},
"end": {
"line": 0,
"character": 67
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfigOptions'."
},
{
"range": {
"start": {
"line": 4,
"character": 39
},
"end": {
"line": 4,
"character": 49
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfig'."
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,21 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"context": {
"diagnostics": [],
"only": [
"refactor"
]
}
}

View file

@ -1,47 +0,0 @@
[
{
"title": "Update specifier to its redirected specifier.",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 60
}
},
"severity": 3,
"code": "redirect",
"source": "deno",
"message": "The import of \"http://127.0.0.1:4545/x_deno_warning.js\" was redirected to \"http://127.0.0.1:4545/lsp/x_deno_warning_redirect.js\".",
"data": {
"specifier": "http://127.0.0.1:4545/x_deno_warning.js",
"redirect": "http://127.0.0.1:4545/lsp/x_deno_warning_redirect.js"
}
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 60
}
},
"newText": "\"http://127.0.0.1:4545/lsp/x_deno_warning_redirect.js\""
}
]
}
}
}
]

View file

@ -1,27 +0,0 @@
{
"title": "Add all missing 'async' modifiers",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 7
}
},
"severity": 1,
"code": 1308,
"source": "deno-ts",
"message": "'await' expressions are only allowed within async functions and at the top levels of modules.",
"relatedInformation": []
}
],
"data": {
"specifier": "file:///a/file.ts",
"fixId": "fixAwaitInSyncFunction"
}
}

View file

@ -1,42 +0,0 @@
{
"title": "Add all missing imports",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 50
},
"end": {
"line": 0,
"character": 67
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfigOptions'."
},
{
"range": {
"start": {
"line": 4,
"character": 39
},
"end": {
"line": 4,
"character": 49
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfig'."
}
],
"data": {
"specifier": "file:///a/file00.ts",
"fixId": "fixMissingImport"
}
}

View file

@ -1,20 +0,0 @@
{
"title": "Extract to interface",
"kind": "refactor.extract.interface",
"isPreferred": true,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 33
}
},
"refactorName": "Extract type",
"actionName": "Extract to interface"
}
}

View file

@ -1,91 +0,0 @@
{
"title": "Add all missing 'async' modifiers",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 7
}
},
"severity": 1,
"code": 1308,
"source": "deno-ts",
"message": "'await' expressions are only allowed within async functions and at the top levels of modules.",
"relatedInformation": []
}
],
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 7
}
},
"newText": "async "
},
{
"range": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 25
}
},
"newText": "Promise<void>"
},
{
"range": {
"start": {
"line": 4,
"character": 7
},
"end": {
"line": 4,
"character": 7
}
},
"newText": "async "
},
{
"range": {
"start": {
"line": 4,
"character": 21
},
"end": {
"line": 4,
"character": 25
}
},
"newText": "Promise<void>"
}
]
}
]
},
"data": {
"specifier": "file:///a/file.ts",
"fixId": "fixAwaitInSyncFunction"
}
}

View file

@ -1,67 +0,0 @@
{
"title": "Add all missing imports",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 50
},
"end": {
"line": 0,
"character": 67
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfigOptions'."
},
{
"range": {
"start": {
"line": 4,
"character": 39
},
"end": {
"line": 4,
"character": 49
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfig'."
}
],
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file00.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"newText": "import { DuckConfig } from \"./file01.ts\";\nimport { DuckConfigOptions } from \"./file02.ts\";\n\n"
}
]
}
]
},
"data": {
"specifier": "file:///a/file00.ts",
"fixId": "fixMissingImport"
}
}

View file

@ -1,58 +0,0 @@
{
"title": "Extract to interface",
"kind": "refactor.extract.interface",
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"newText": "interface NewType {\n a?: number;\n b?: string;\n}\n\n"
},
{
"range": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 33
}
},
"newText": "NewType"
}
]
}
]
},
"isPreferred": true,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 33
}
},
"refactorName": "Extract type",
"actionName": "Extract to interface"
}
}

View file

@ -1,90 +0,0 @@
[
{
"title": "Add async modifier to containing function",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 7
}
},
"severity": 1,
"code": 1308,
"source": "deno-ts",
"message": "'await' expressions are only allowed within async functions and at the top levels of modules.",
"relatedInformation": []
}
],
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 7
}
},
"newText": "async "
},
{
"range": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 25
}
},
"newText": "Promise<void>"
}
]
}
]
}
},
{
"title": "Add all missing 'async' modifiers",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 7
}
},
"severity": 1,
"code": 1308,
"source": "deno-ts",
"message": "'await' expressions are only allowed within async functions and at the top levels of modules.",
"relatedInformation": []
}
],
"data": {
"specifier": "file:///a/file.ts",
"fixId": "fixAwaitInSyncFunction"
}
}
]

View file

@ -1,36 +0,0 @@
[
{
"title": "Cache \"https://deno.land/x/a/mod.ts\" and its dependencies.",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 49
}
},
"severity": 1,
"code": "no-cache",
"source": "deno",
"message": "Unable to load the remote module: \"https://deno.land/x/a/mod.ts\".",
"data": {
"specifier": "https://deno.land/x/a/mod.ts"
}
}
],
"command": {
"title": "",
"command": "deno.cache",
"arguments": [
[
"https://deno.land/x/a/mod.ts"
]
]
}
}
]

View file

@ -1,43 +0,0 @@
[
{
"title": "Insert import assertion.",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 14
},
"end": {
"line": 0,
"character": 27
}
},
"severity": 1,
"code": "no-assert-type",
"source": "deno",
"message": "The module is a JSON module and not being imported with an import assertion. Consider adding `assert { type: \"json\" }` to the import statement."
}
],
"edit": {
"changes": {
"file:///a/a.ts": [
{
"range": {
"start": {
"line": 0,
"character": 27
},
"end": {
"line": 0,
"character": 27
}
},
"newText": " assert { type: \"json\" }"
}
]
}
}
}
]

View file

@ -1,122 +0,0 @@
[
{
"title": "Add import from \"./file02.ts\"",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 50
},
"end": {
"line": 0,
"character": 67
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfigOptions'."
}
],
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file00.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"newText": "import { DuckConfigOptions } from \"./file02.ts\";\n\n"
}
]
}
]
}
},
{
"title": "Add all missing imports",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 50
},
"end": {
"line": 0,
"character": 67
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfigOptions'."
}
],
"data": {
"specifier": "file:///a/file00.ts",
"fixId": "fixMissingImport"
}
},
{
"title": "Add import from \"./file01.ts\"",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 4,
"character": 39
},
"end": {
"line": 4,
"character": 49
}
},
"severity": 1,
"code": 2304,
"source": "deno-ts",
"message": "Cannot find name 'DuckConfig'."
}
],
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file00.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"newText": "import { DuckConfig } from \"./file01.ts\";\n\n"
}
]
}
]
}
}
]

View file

@ -1,42 +0,0 @@
[
{
"title": "Extract to function in module scope",
"kind": "refactor.extract.function",
"isPreferred": false,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 14,
"character": 0
}
},
"refactorName": "Extract Symbol",
"actionName": "function_scope_0"
}
},
{
"title": "Move to a new file",
"kind": "refactor.move.newFile",
"isPreferred": false,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 14,
"character": 0
}
},
"refactorName": "Move to a new file",
"actionName": "Move to a new file"
}
}
]

View file

@ -1,177 +0,0 @@
[
{
"title": "Extract to function in module scope",
"kind": "refactor.extract.function",
"isPreferred": false,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Extract Symbol",
"actionName": "function_scope_0"
}
},
{
"title": "Extract to constant in enclosing scope",
"kind": "refactor.extract.constant",
"isPreferred": false,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Extract Symbol",
"actionName": "constant_scope_0"
}
},
{
"title": "Move to a new file",
"kind": "refactor.move.newFile",
"isPreferred": false,
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Move to a new file",
"actionName": "Move to a new file"
}
},
{
"title": "Convert default export to named export",
"kind": "refactor.rewrite.export.named",
"isPreferred": false,
"disabled": {
"reason": "This file already has a default export"
},
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Convert export",
"actionName": "Convert default export to named export"
}
},
{
"title": "Convert named export to default export",
"kind": "refactor.rewrite.export.default",
"isPreferred": false,
"disabled": {
"reason": "This file already has a default export"
},
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Convert export",
"actionName": "Convert named export to default export"
}
},
{
"title": "Convert namespace import to named imports",
"kind": "refactor.rewrite.import.named",
"isPreferred": false,
"disabled": {
"reason": "Selection is not an import declaration."
},
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Convert import",
"actionName": "Convert namespace import to named imports"
}
},
{
"title": "Convert named imports to default import",
"kind": "refactor.rewrite.import.default",
"isPreferred": false,
"disabled": {
"reason": "Selection is not an import declaration."
},
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Convert import",
"actionName": "Convert named imports to default import"
}
},
{
"title": "Convert named imports to namespace import",
"kind": "refactor.rewrite.import.namespace",
"isPreferred": false,
"disabled": {
"reason": "Selection is not an import declaration."
},
"data": {
"specifier": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"refactorName": "Convert import",
"actionName": "Convert named imports to namespace import"
}
}
]

View file

@ -1,39 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 3,
"character": 5
},
"end": {
"line": 3,
"character": 15
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 3,
"character": 5
},
"end": {
"line": 3,
"character": 15
}
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'snake_case' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,92 +0,0 @@
[
{
"title": "Disable prefer-const for this line",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": { "line": 3, "character": 5 },
"end": { "line": 3, "character": 15 }
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'snake_case' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": { "line": 3, "character": 0 },
"end": { "line": 3, "character": 0 }
},
"newText": "// deno-lint-ignore prefer-const\n"
}
]
}
}
},
{
"title": "Disable prefer-const for the entire file",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": { "line": 3, "character": 5 },
"end": { "line": 3, "character": 15 }
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'snake_case' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": { "line": 1, "character": 34 },
"end": { "line": 1, "character": 34 }
},
"newText": " prefer-const"
}
]
}
}
},
{
"title": "Ignore lint errors for the entire file",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": { "line": 3, "character": 5 },
"end": { "line": 3, "character": 15 }
},
"severity": 1,
"code": "prefer-const",
"source": "deno-lint",
"message": "'snake_case' is never reassigned\nUse 'const' instead",
"relatedInformation": []
}
],
"edit": {
"changes": {
"file:///a/file.ts": [
{
"range": {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 }
},
"newText": "// deno-lint-ignore-file\n"
}
]
}
}
}
]

View file

@ -1,41 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"range": {
"start": {
"line": 0,
"character": 18
},
"end": {
"line": 0,
"character": 29
}
},
"context": {
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 18
},
"end": {
"line": 0,
"character": 29
}
},
"severity": 1,
"code": "no-cache-npm",
"source": "deno",
"message": "Uncached or missing npm package: \"chalk\".",
"data": {
"specifier": "npm:chalk"
}
}
],
"only": [
"quickfix"
]
}
}

View file

@ -1,36 +0,0 @@
[
{
"title": "Cache \"npm:chalk\" and its dependencies.",
"kind": "quickfix",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 18
},
"end": {
"line": 0,
"character": 29
}
},
"severity": 1,
"code": "no-cache-npm",
"source": "deno",
"message": "Uncached or missing npm package: \"chalk\".",
"data": {
"specifier": "npm:chalk"
}
}
],
"command": {
"title": "",
"command": "deno.cache",
"arguments": [
[
"npm:chalk"
]
]
}
}
]

View file

@ -1,25 +0,0 @@
{
"uri": "file:///a/file.ts",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 18
},
"end": {
"line": 0,
"character": 29
}
},
"severity": 1,
"code": "no-cache-npm",
"source": "deno",
"message": "Uncached or missing npm package: \"chalk\".",
"data": {
"specifier": "npm:chalk"
}
}
],
"version": 1
}

View file

@ -1,51 +0,0 @@
{
"range": {
"start": {
"line": 0,
"character": 6
},
"end": {
"line": 0,
"character": 7
}
},
"command": {
"title": "2 references",
"command": "deno.showReferences",
"arguments": [
"file:///a/file.ts",
{
"line": 0,
"character": 6
},
[
{
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 6
},
"end": {
"line": 0,
"character": 7
}
}
},
{
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 12,
"character": 14
},
"end": {
"line": 12,
"character": 15
}
}
}
]
]
}
}

View file

@ -1,38 +0,0 @@
{
"range": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 11
}
},
"command": {
"title": "1 implementation",
"command": "deno.showReferences",
"arguments": [
"file:///a/file.ts",
{
"line": 0,
"character": 10
},
[
{
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 4,
"character": 6
},
"end": {
"line": 4,
"character": 7
}
}
}
]
]
}
}

View file

@ -1,34 +0,0 @@
[
{
"range": {
"start": {
"line": 0,
"character": 6
},
"end": {
"line": 0,
"character": 7
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
},
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 3
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
}
]

View file

@ -1,50 +0,0 @@
[
{
"range": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 11
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "implementations"
}
},
{
"range": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 11
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
},
{
"range": {
"start": {
"line": 4,
"character": 6
},
"end": {
"line": 4,
"character": 7
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
}
]

View file

@ -1,98 +0,0 @@
[
{
"range": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 11
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "implementations"
}
},
{
"range": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 11
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
},
{
"range": {
"start": {
"line": 4,
"character": 6
},
"end": {
"line": 4,
"character": 7
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
},
{
"range": {
"start": {
"line": 10,
"character": 10
},
"end": {
"line": 10,
"character": 11
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "implementations"
}
},
{
"range": {
"start": {
"line": 10,
"character": 10
},
"end": {
"line": 10,
"character": 11
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
},
{
"range": {
"start": {
"line": 11,
"character": 2
},
"end": {
"line": 11,
"character": 3
}
},
"data": {
"specifier": "file:///a/file.ts",
"source": "references"
}
}
]

View file

@ -1,370 +0,0 @@
[
{
"range": {
"start": {
"line": 4,
"character": 5
},
"end": {
"line": 4,
"character": 9
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test a",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 4,
"character": 5
},
"end": {
"line": 4,
"character": 9
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test a",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 5,
"character": 5
},
"end": {
"line": 5,
"character": 9
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test b",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 5,
"character": 5
},
"end": {
"line": 5,
"character": 9
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test b",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 9,
"character": 0
},
"end": {
"line": 9,
"character": 4
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test c",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 9,
"character": 0
},
"end": {
"line": 9,
"character": 4
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test c",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 13,
"character": 0
},
"end": {
"line": 13,
"character": 4
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test d",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 13,
"character": 0
},
"end": {
"line": 13,
"character": 4
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test d",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 14,
"character": 0
},
"end": {
"line": 14,
"character": 5
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test e",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 14,
"character": 0
},
"end": {
"line": 14,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test e",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 18,
"character": 0
},
"end": {
"line": 18,
"character": 5
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test f",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 18,
"character": 0
},
"end": {
"line": 18,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test f",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 19,
"character": 0
},
"end": {
"line": 19,
"character": 5
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test g",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 19,
"character": 0
},
"end": {
"line": 19,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test g",
{
"inspect": true
}
]
}
},
{
"range": {
"start": {
"line": 23,
"character": 0
},
"end": {
"line": 23,
"character": 5
}
},
"command": {
"title": "▶︎ Run Test",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test h",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 23,
"character": 0
},
"end": {
"line": 23,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test h",
{
"inspect": true
}
]
}
}
]

View file

@ -1,13 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts"
},
"position": {
"line": 8,
"character": 4
},
"context": {
"triggerKind": 2,
"triggerCharacter": "."
}
}

View file

@ -1,51 +0,0 @@
{
"isIncomplete": false,
"items": [
{
"label": ".",
"kind": 19,
"detail": "(local)",
"sortText": "1",
"insertText": ".",
"commitCharacters": [
"\"",
"'"
]
},
{
"label": "..",
"kind": 19,
"detail": "(local)",
"sortText": "1",
"insertText": "..",
"commitCharacters": [
"\"",
"'"
]
},
{
"label": "http://localhost:4545",
"kind": 19,
"detail": "(registry)",
"sortText": "2",
"textEdit": {
"range": {
"start": {
"line": 0,
"character": 20
},
"end": {
"line": 0,
"character": 20
}
},
"newText": "http://localhost:4545"
},
"commitCharacters": [
"\"",
"'",
"/"
]
}
]
}

View file

@ -1,14 +0,0 @@
{
"label": "build",
"kind": 6,
"sortText": "1",
"insertTextFormat": 1,
"data": {
"tsc": {
"specifier": "file:///a/file.ts",
"position": 5,
"name": "build",
"useCodeSnippet": false
}
}
}

View file

@ -1,15 +0,0 @@
{
"label": "b?",
"kind": 5,
"sortText": "1",
"filterText": "b",
"insertText": "b",
"data": {
"tsc": {
"specifier": "file:///a/file.ts",
"position": 79,
"name": "b",
"useCodeSnippet": false
}
}
}

View file

@ -1,20 +0,0 @@
{
"label": "v2.0.0",
"kind": 19,
"detail": "(version)",
"sortText": "0000000003",
"filterText": "http://localhost:4545/x/a@v2.0.0",
"textEdit": {
"range": {
"start": {
"line": 0,
"character": 20
},
"end": {
"line": 0,
"character": 46
}
},
"newText": "http://localhost:4545/x/a@v2.0.0"
}
}

View file

@ -1,11 +0,0 @@
{
"label": "build",
"kind": 6,
"detail": "const Deno.build: {\n target: string;\n arch: \"x86_64\" | \"aarch64\";\n os: \"darwin\" | \"linux\" | \"windows\" | \"freebsd\" | \"netbsd\" | \"aix\" | \"solaris\" | \"illumos\";\n vendor: string;\n env?: string | undefined;\n}",
"documentation": {
"kind": "markdown",
"value": "Information related to the build of the current Deno runtime.\n\nUsers are discouraged from code branching based on this information, as\nassumptions about what is available in what build environment might change\nover time. Developers should specifically sniff out the features they\nintend to use.\n\nThe intended use for the information is for logging and debugging purposes.\n\n*@category* - Runtime Environment"
},
"sortText": "1",
"insertTextFormat": 1
}

View file

@ -1,20 +0,0 @@
{
"label": "v2.0.0",
"kind": 19,
"detail": "(version)",
"sortText": "0000000003",
"filterText": "http://localhost:4545/x/a@v2.0.0",
"textEdit": {
"range": {
"start": {
"line": 0,
"character": 20
},
"end": {
"line": 0,
"character": 46
}
},
"newText": "http://localhost:4545/x/a@v2.0.0"
}
}

View file

@ -1,14 +0,0 @@
{
"label": "MyClass",
"kind": 6,
"sortText": "1",
"insertTextFormat": 1,
"data": {
"tsc": {
"specifier": "file:///a/file.ts",
"position": 69,
"name": "MyClass",
"useCodeSnippet": false
}
}
}

View file

@ -1,14 +0,0 @@
{
"label": "MyClass",
"kind": 6,
"sortText": "1",
"insertTextFormat": 1,
"data": {
"tsc": {
"specifier": "file:///a/file.ts",
"position": 69,
"name": "MyClass",
"useCodeSnippet": false
}
}
}

View file

@ -1,5 +0,0 @@
{
"imports": {
"/~/": "./lib/"
}
}

View file

@ -1,16 +0,0 @@
{
"fmt": {
"files": {
"exclude": [
"ignored.ts"
]
},
"options": {
"useTabs": true,
"lineWidth": 40,
"indentWidth": 8,
"singleQuote": true,
"proseWrap": "always"
}
}
}

View file

@ -1,11 +0,0 @@
{
"fmt": {
"options": {
"useTabs": true,
"lineWidth": 40,
"indentWidth": 8,
"singleQuote": true,
"proseWrap": "always"
}
}
}

View file

@ -1,13 +0,0 @@
{
"lint": {
"rules": {
"exclude": [
"camelcase"
],
"include": [
"ban-untagged-todo"
],
"tags": []
}
}
}

View file

@ -1,25 +0,0 @@
{
"uri": "file:///a/file.ts",
"diagnostics": [
{
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 49
}
},
"severity": 1,
"code": "no-cache",
"source": "deno",
"message": "Uncached or missing remote URL: \"https://deno.land/x/a/mod.ts\".",
"data": {
"specifier": "https://deno.land/x/a/mod.ts"
}
}
],
"version": 1
}

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "// TODO: fixme\nexport async function non_camel_case() {\nconsole.log(\"finished!\")\n}"
}
}

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "/// <reference types=\"https://example.com/a/b.d.ts\" />\n/// <reference path=\"https://example.com/a/c.ts\"\n\n// @deno-types=https://example.com/a/d.d.ts\nimport * as d from \"https://example.com/a/d.js\";\n\n// @deno-types=\"https://example.com/a/e.d.ts\"\nimport * as e from \"https://example.com/a/e.js\";\n\nconsole.log(d, e);\n"
}
}

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "interface IFoo {\n foo(): boolean;\n}\n\nclass Bar implements IFoo {\n constructor(public x: number) { }\n foo() { return true; }\n /** @deprecated */\n baz() { return false; }\n get value(): number { return 0; }\n set value(newVavlue: number) { return; }\n static staticBar = new Bar(0);\n private static getStaticBar() { return Bar.staticBar; }\n}\n\nenum Values { value1, value2 }\n\nvar bar: IFoo = new Bar(3);"
}
}

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @deno-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n"
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "enum Values { value1, value2 }\n\nasync function baz(s: string): Promise<string> {\n const r = s.slice(0);\n return r;\n}\n\ninterface IFoo {\n readonly x: number;\n foo(): boolean;\n}\n\nclass Bar implements IFoo {\n constructor(public readonly x: number) { }\n foo() { return true; }\n static staticBar = new Bar(0);\n private static getStaticBar() { return Bar.staticBar; }\n}\n"
}
}

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "const { test } = Deno;\nconst { test: test2 } = Deno;\nconst test3 = Deno.test;\n\nDeno.test(\"test a\", () => {});\nDeno.test({\n name: \"test b\",\n fn() {},\n});\ntest({\n name: \"test c\",\n fn() {},\n});\ntest(\"test d\", () => {});\ntest2({\n name: \"test e\",\n fn() {},\n});\ntest2(\"test f\", () => {});\ntest3({\n name: \"test g\",\n fn() {},\n});\ntest3(\"test h\", () => {});\n"
}
}

View file

@ -1,8 +0,0 @@
{
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "import * as a from \"https://localhost:5545/xTypeScriptTypes.js\";\n// @deno-types=\"https://localhost:5545/type_definitions/foo.d.ts\"\nimport * as b from \"https://localhost:5545/type_definitions/foo.js\";\nimport * as c from \"https://localhost:5545/subdir/type_reference.js\";\nimport * as d from \"https://localhost:5545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n"
}
}

View file

@ -1,371 +0,0 @@
[
{
"name": "bar",
"kind": 13,
"range": {
"start": {
"line": 17,
"character": 4
},
"end": {
"line": 17,
"character": 26
}
},
"selectionRange": {
"start": {
"line": 17,
"character": 4
},
"end": {
"line": 17,
"character": 7
}
}
},
{
"name": "Bar",
"kind": 5,
"range": {
"start": {
"line": 4,
"character": 0
},
"end": {
"line": 13,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 4,
"character": 6
},
"end": {
"line": 4,
"character": 9
}
},
"children": [
{
"name": "constructor",
"kind": 9,
"range": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 5,
"character": 35
}
},
"selectionRange": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 5,
"character": 35
}
}
},
{
"name": "baz",
"kind": 6,
"tags": [
1
],
"range": {
"start": {
"line": 8,
"character": 2
},
"end": {
"line": 8,
"character": 25
}
},
"selectionRange": {
"start": {
"line": 8,
"character": 2
},
"end": {
"line": 8,
"character": 5
}
}
},
{
"name": "foo",
"kind": 6,
"range": {
"start": {
"line": 6,
"character": 2
},
"end": {
"line": 6,
"character": 24
}
},
"selectionRange": {
"start": {
"line": 6,
"character": 2
},
"end": {
"line": 6,
"character": 5
}
}
},
{
"name": "getStaticBar",
"kind": 6,
"range": {
"start": {
"line": 12,
"character": 2
},
"end": {
"line": 12,
"character": 57
}
},
"selectionRange": {
"start": {
"line": 12,
"character": 17
},
"end": {
"line": 12,
"character": 29
}
}
},
{
"name": "staticBar",
"kind": 8,
"range": {
"start": {
"line": 11,
"character": 2
},
"end": {
"line": 11,
"character": 32
}
},
"selectionRange": {
"start": {
"line": 11,
"character": 9
},
"end": {
"line": 11,
"character": 18
}
}
},
{
"name": "(get) value",
"kind": 8,
"range": {
"start": {
"line": 9,
"character": 2
},
"end": {
"line": 9,
"character": 35
}
},
"selectionRange": {
"start": {
"line": 9,
"character": 6
},
"end": {
"line": 9,
"character": 11
}
}
},
{
"name": "(set) value",
"kind": 8,
"range": {
"start": {
"line": 10,
"character": 2
},
"end": {
"line": 10,
"character": 42
}
},
"selectionRange": {
"start": {
"line": 10,
"character": 6
},
"end": {
"line": 10,
"character": 11
}
}
},
{
"name": "x",
"kind": 8,
"range": {
"start": {
"line": 5,
"character": 14
},
"end": {
"line": 5,
"character": 30
}
},
"selectionRange": {
"start": {
"line": 5,
"character": 21
},
"end": {
"line": 5,
"character": 22
}
}
}
]
},
{
"name": "IFoo",
"kind": 11,
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 2,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 14
}
},
"children": [
{
"name": "foo",
"kind": 6,
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 17
}
},
"selectionRange": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 5
}
}
}
]
},
{
"name": "Values",
"kind": 10,
"range": {
"start": {
"line": 15,
"character": 0
},
"end": {
"line": 15,
"character": 30
}
},
"selectionRange": {
"start": {
"line": 15,
"character": 5
},
"end": {
"line": 15,
"character": 11
}
},
"children": [
{
"name": "value1",
"kind": 22,
"range": {
"start": {
"line": 15,
"character": 14
},
"end": {
"line": 15,
"character": 20
}
},
"selectionRange": {
"start": {
"line": 15,
"character": 14
},
"end": {
"line": 15,
"character": 20
}
}
},
{
"name": "value2",
"kind": 22,
"range": {
"start": {
"line": 15,
"character": 22
},
"end": {
"line": 15,
"character": 28
}
},
"selectionRange": {
"start": {
"line": 15,
"character": 22
},
"end": {
"line": 15,
"character": 28
}
}
}
]
}
]

View file

@ -1,54 +0,0 @@
[
{
"range": {
"start": {
"line": 0,
"character": 12
},
"end": {
"line": 0,
"character": 13
}
},
"newText": "\""
},
{
"range": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 22
}
},
"newText": "\";"
},
{
"range": {
"start": {
"line": 1,
"character": 12
},
"end": {
"line": 1,
"character": 13
}
},
"newText": "\""
},
{
"range": {
"start": {
"line": 1,
"character": 23
},
"end": {
"line": 1,
"character": 25
}
},
"newText": "\");"
}
]

View file

@ -1,7 +0,0 @@
{
"imports": {
"/~/": "./lib/",
"fs": "https://example.com/fs/index.js",
"std/": "https://example.com/std@0.123.0/"
}
}

View file

@ -1,28 +0,0 @@
{
"item": {
"name": "baz",
"kind": 6,
"detail": "Bar",
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 7,
"character": 3
}
},
"selectionRange": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 5,
"character": 5
}
}
}
}

View file

@ -1,42 +0,0 @@
[
{
"from": {
"name": "main",
"kind": 12,
"detail": "",
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 10,
"character": 0
},
"end": {
"line": 13,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 10,
"character": 9
},
"end": {
"line": 10,
"character": 13
}
}
},
"fromRanges": [
{
"start": {
"line": 12,
"character": 6
},
"end": {
"line": 12,
"character": 9
}
}
]
}
]

View file

@ -1,82 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"certificateStores": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": null,
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"testing": {
"args": [
"--allow-all"
],
"enable": true
},
"tlsCertificate": null,
"unsafelyIgnoreCertificateErrors": null,
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"completion": {
"completionItem": {
"snippetSupport": true
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
},
"experimental": {
"testingApi": true
}
}
}

View file

@ -1,65 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": "bad_tsconfig.json",
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,64 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": "",
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,59 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,64 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"codeLens": {
"implementations": true,
"references": true,
"test": false
},
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,65 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"codeLens": {
"implementations": true,
"references": true
},
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {
"http://localhost:4545/": false
}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,63 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": false,
"cache": null,
"codeLens": {
"implementations": true,
"references": true
},
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,102 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"certificateStores": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": null,
"importMap": null,
"inlayHints": {
"parameterNames": {
"enabled": "all"
},
"parameterTypes": {
"enabled": true
},
"variableTypes": {
"enabled": true
},
"propertyDeclarationTypes": {
"enabled": true
},
"functionLikeReturnTypes": {
"enabled": true
},
"enumMemberValues": {
"enabled": true
}
},
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"testing": {
"args": [
"--allow-all"
],
"enable": true
},
"tlsCertificate": null,
"unsafelyIgnoreCertificateErrors": null,
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"completion": {
"completionItem": {
"snippetSupport": true
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
},
"experimental": {
"testingApi": true
}
}
}

View file

@ -1,62 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"codeLens": {
"implementations": true,
"references": true
},
"importMap": "data:application/json;utf8,{\"imports\": { \"example\": \"https://deno.land/x/example/mod.ts\" }}",
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {
"http://localhost:4545/": false
}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,77 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"certificateStores": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": null,
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"testing": {
"args": [
"--allow-all"
],
"enable": true
},
"tlsCertificate": null,
"unsafelyIgnoreCertificateErrors": null,
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
},
"experimental": {
"testingApi": true
}
}
}

View file

@ -1,67 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": "",
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {
"http://localhost:4545/": true
}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,71 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"certificateStores": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": "",
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {
"https://localhost:5545": true,
"http://localhost:4545": true
}
}
},
"tlsCertificate": "tls/RootCA.pem",
"unsafelyIgnoreCertificateErrors": null,
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,63 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"cache": null,
"codeLens": {
"implementations": true,
"references": true
},
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": true
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

View file

@ -1,77 +0,0 @@
{
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": "file:///project/",
"initializationOptions": {
"enable": false,
"enablePaths": [
"./worker"
],
"cache": null,
"certificateStores": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": "",
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"tlsCertificate": null,
"unsafelyIgnoreCertificateErrors": null,
"unstable": false
},
"workspaceFolders": [
{
"uri": "file:///project/",
"name": "project"
}
],
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix",
"refactor"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"disabledSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}

676
cli/tests/testdata/lsp/large_file.txt vendored Normal file
View file

@ -0,0 +1,676 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// @ts-check
/// <reference path="./compiler.d.ts" />
// deno-lint-ignore-file no-undef
// This module is the entry point for "compiler" isolate, ie. the one
// that is created when Deno needs to type check TypeScript, and in some
// instances convert TypeScript to JavaScript.
// Removes the `__proto__` for security reasons. This intentionally makes
// Deno non compliant with ECMA-262 Annex B.2.2.1
delete Object.prototype.__proto__;
((window) => {
/** @type {DenoCore} */
const core = window.Deno.core;
let logDebug = false;
let logSource = "JS";
function setLogDebug(debug, source) {
logDebug = debug;
if (source) {
logSource = source;
}
}
function debug(...args) {
if (logDebug) {
const stringifiedArgs = args.map((arg) =>
typeof arg === "string" ? arg : JSON.stringify(arg)
).join(" ");
// adding a non-zero integer value to the end of the debug string causes
// the message to be printed to stderr instead of stdout, which is better
// aligned to the behaviour of debug messages
core.print(`DEBUG ${logSource} - ${stringifiedArgs}\n`, 1);
}
}
function error(...args) {
const stringifiedArgs = args.map((arg) =>
typeof arg === "string" || arg instanceof Error
? String(arg)
: JSON.stringify(arg)
).join(" ");
core.print(`ERROR ${logSource} = ${stringifiedArgs}\n`, 1);
}
class AssertionError extends Error {
constructor(msg) {
super(msg);
this.name = "AssertionError";
}
}
function assert(cond, msg = "Assertion failed.") {
if (!cond) {
throw new AssertionError(msg);
}
}
/** @type {Map<string, ts.SourceFile>} */
const sourceFileCache = new Map();
/** @param {ts.DiagnosticRelatedInformation} diagnostic */
function fromRelatedInformation({
start,
length,
file,
messageText: msgText,
...ri
}) {
let messageText;
let messageChain;
if (typeof msgText === "object") {
messageChain = msgText;
} else {
messageText = msgText;
}
if (start !== undefined && length !== undefined && file) {
const startPos = file.getLineAndCharacterOfPosition(start);
const sourceLine = file.getFullText().split("\n")[startPos.line];
const fileName = file.fileName;
return {
start: startPos,
end: file.getLineAndCharacterOfPosition(start + length),
fileName,
messageChain,
messageText,
sourceLine,
...ri,
};
} else {
return {
messageChain,
messageText,
...ri,
};
}
}
/** @param {ts.Diagnostic[]} diagnostics */
function fromTypeScriptDiagnostic(diagnostics) {
return diagnostics.map(({ relatedInformation: ri, source, ...diag }) => {
/** @type {any} */
const value = fromRelatedInformation(diag);
value.relatedInformation = ri
? ri.map(fromRelatedInformation)
: undefined;
value.source = source;
return value;
});
}
// Using incremental compile APIs requires that all
// paths must be either relative or absolute. Since
// analysis in Rust operates on fully resolved URLs,
// it makes sense to use the same scheme here.
const ASSETS = "asset:///";
const CACHE = "cache:///";
/** Diagnostics that are intentionally ignored when compiling TypeScript in
* Deno, as they provide misleading or incorrect information. */
const IGNORED_DIAGNOSTICS = [
// TS1208: All files must be modules when the '--isolatedModules' flag is
// provided. We can ignore because we guarantee that all files are
// modules.
1208,
// TS1375: 'await' expressions are only allowed at the top level of a file
// when that file is a module, but this file has no imports or exports.
// Consider adding an empty 'export {}' to make this file a module.
1375,
// TS1103: 'for-await-of' statement is only allowed within an async function
// or async generator.
1103,
// TS2306: File 'file:///Users/rld/src/deno/subdir/amd_like.js' is
// not a module.
2306,
// TS2691: An import path cannot end with a '.ts' extension. Consider
// importing 'bad-module' instead.
2691,
// TS2792: Cannot find module. Did you mean to set the 'moduleResolution'
// option to 'node', or to add aliases to the 'paths' option?
2792,
// TS5009: Cannot find the common subdirectory path for the input files.
5009,
// TS5055: Cannot write file
// 'http://localhost:4545/subdir/mt_application_x_javascript.j4.js'
// because it would overwrite input file.
5055,
// TypeScript is overly opinionated that only CommonJS modules kinds can
// support JSON imports. Allegedly this was fixed in
// Microsoft/TypeScript#26825 but that doesn't seem to be working here,
// so we will ignore complaints about this compiler setting.
5070,
// TS7016: Could not find a declaration file for module '...'. '...'
// implicitly has an 'any' type. This is due to `allowJs` being off by
// default but importing of a JavaScript module.
7016,
];
const SNAPSHOT_COMPILE_OPTIONS = {
esModuleInterop: true,
jsx: ts.JsxEmit.React,
module: ts.ModuleKind.ESNext,
noEmit: true,
strict: true,
target: ts.ScriptTarget.ESNext,
};
class ScriptSnapshot {
/** @type {string} */
specifier;
/** @type {string} */
version;
/**
* @param {string} specifier
* @param {string} version
*/
constructor(specifier, version) {
this.specifier = specifier;
this.version = version;
}
/**
* @param {number} start
* @param {number} end
* @returns {string}
*/
getText(start, end) {
const { specifier, version } = this;
debug(
`snapshot.getText(${start}, ${end}) specifier: ${specifier} version: ${version}`,
);
return core.jsonOpSync("op_get_text", { specifier, version, start, end });
}
/**
* @returns {number}
*/
getLength() {
const { specifier, version } = this;
debug(`snapshot.getLength() specifier: ${specifier} version: ${version}`);
return core.jsonOpSync("op_get_length", { specifier, version });
}
/**
* @param {ScriptSnapshot} oldSnapshot
* @returns {ts.TextChangeRange | undefined}
*/
getChangeRange(oldSnapshot) {
const { specifier, version } = this;
const { version: oldVersion } = oldSnapshot;
const oldLength = oldSnapshot.getLength();
debug(
`snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`,
);
return core.jsonOpSync(
"op_get_change_range",
{ specifier, oldLength, oldVersion, version },
);
}
dispose() {
const { specifier, version } = this;
debug(`snapshot.dispose() specifier: ${specifier} version: ${version}`);
core.jsonOpSync("op_dispose", { specifier, version });
}
}
/** @type {ts.CompilerOptions} */
let compilationSettings = {};
/** @type {ts.LanguageService} */
let languageService;
/** An object literal of the incremental compiler host, which provides the
* specific "bindings" to the Deno environment that tsc needs to work.
*
* @type {ts.CompilerHost & ts.LanguageServiceHost} */
const host = {
fileExists(fileName) {
debug(`host.fileExists("${fileName}")`);
return false;
},
readFile(specifier) {
debug(`host.readFile("${specifier}")`);
return core.jsonOpSync("op_load", { specifier }).data;
},
getSourceFile(
specifier,
languageVersion,
_onError,
_shouldCreateNewSourceFile,
) {
debug(
`host.getSourceFile("${specifier}", ${
ts.ScriptTarget[languageVersion]
})`,
);
let sourceFile = sourceFileCache.get(specifier);
if (sourceFile) {
return sourceFile;
}
/** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */
const { data, hash, scriptKind } = core.jsonOpSync(
"op_load",
{ specifier },
);
assert(
data != null,
`"data" is unexpectedly null for "${specifier}".`,
);
sourceFile = ts.createSourceFile(
specifier,
data,
languageVersion,
false,
scriptKind,
);
sourceFile.moduleName = specifier;
sourceFile.version = hash;
sourceFileCache.set(specifier, sourceFile);
return sourceFile;
},
getDefaultLibFileName() {
return `${ASSETS}/lib.esnext.d.ts`;
},
getDefaultLibLocation() {
return ASSETS;
},
writeFile(fileName, data, _writeByteOrderMark, _onError, sourceFiles) {
debug(`host.writeFile("${fileName}")`);
let maybeSpecifiers;
if (sourceFiles) {
maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName);
}
return core.jsonOpSync(
"op_emit",
{ maybeSpecifiers, fileName, data },
);
},
getCurrentDirectory() {
return CACHE;
},
getCanonicalFileName(fileName) {
return fileName;
},
useCaseSensitiveFileNames() {
return true;
},
getNewLine() {
return "\n";
},
resolveModuleNames(specifiers, base) {
debug(`host.resolveModuleNames()`);
debug(` base: ${base}`);
debug(` specifiers: ${specifiers.join(", ")}`);
/** @type {Array<[string, ts.Extension] | undefined>} */
const resolved = core.jsonOpSync("op_resolve", {
specifiers,
base,
});
if (resolved) {
const result = resolved.map((item) => {
if (item) {
const [resolvedFileName, extension] = item;
return {
resolvedFileName,
extension,
isExternalLibraryImport: false,
};
}
return undefined;
});
result.length = specifiers.length;
return result;
} else {
return new Array(specifiers.length);
}
},
createHash(data) {
return core.jsonOpSync("op_create_hash", { data }).hash;
},
// LanguageServiceHost
getCompilationSettings() {
debug("host.getCompilationSettings()");
return compilationSettings;
},
getScriptFileNames() {
debug("host.getScriptFileNames()");
return core.jsonOpSync("op_script_names", undefined);
},
getScriptVersion(specifier) {
debug(`host.getScriptVersion("${specifier}")`);
const sourceFile = sourceFileCache.get(specifier);
if (sourceFile) {
return sourceFile.version ?? "1";
}
return core.jsonOpSync("op_script_version", { specifier });
},
getScriptSnapshot(specifier) {
debug(`host.getScriptSnapshot("${specifier}")`);
const sourceFile = sourceFileCache.get(specifier);
if (sourceFile) {
return {
getText(start, end) {
return sourceFile.text.substring(start, end);
},
getLength() {
return sourceFile.text.length;
},
getChangeRange() {
return undefined;
},
};
}
/** @type {string | undefined} */
const version = core.jsonOpSync("op_script_version", { specifier });
if (version != null) {
return new ScriptSnapshot(specifier, version);
}
return undefined;
},
};
/** @type {Array<[string, number]>} */
const stats = [];
let statsStart = 0;
function performanceStart() {
stats.length = 0;
statsStart = Date.now();
ts.performance.enable();
}
/**
* @param {{ program: ts.Program | ts.EmitAndSemanticDiagnosticsBuilderProgram, fileCount?: number }} options
*/
function performanceProgram({ program, fileCount }) {
if (program) {
if ("getProgram" in program) {
program = program.getProgram();
}
stats.push(["Files", program.getSourceFiles().length]);
stats.push(["Nodes", program.getNodeCount()]);
stats.push(["Identifiers", program.getIdentifierCount()]);
stats.push(["Symbols", program.getSymbolCount()]);
stats.push(["Types", program.getTypeCount()]);
stats.push(["Instantiations", program.getInstantiationCount()]);
} else if (fileCount != null) {
stats.push(["Files", fileCount]);
}
const programTime = ts.performance.getDuration("Program");
const bindTime = ts.performance.getDuration("Bind");
const checkTime = ts.performance.getDuration("Check");
const emitTime = ts.performance.getDuration("Emit");
stats.push(["Parse time", programTime]);
stats.push(["Bind time", bindTime]);
stats.push(["Check time", checkTime]);
stats.push(["Emit time", emitTime]);
stats.push(
["Total TS time", programTime + bindTime + checkTime + emitTime],
);
}
function performanceEnd() {
const duration = Date.now() - statsStart;
stats.push(["Compile time", duration]);
return stats;
}
/**
* @typedef {object} Request
* @property {Record<string, any>} config
* @property {boolean} debug
* @property {string[]} rootNames
*/
/** The API that is called by Rust when executing a request.
* @param {Request} request
*/
function exec({ config, debug: debugFlag, rootNames }) {
setLogDebug(debugFlag, "TS");
performanceStart();
debug(">>> exec start", { rootNames });
debug(config);
const { options, errors: configFileParsingDiagnostics } = ts
.convertCompilerOptionsFromJson(config, "");
// The `allowNonTsExtensions` is a "hidden" compiler option used in VSCode
// which is not allowed to be passed in JSON, we need it to allow special
// URLs which Deno supports. So we need to either ignore the diagnostic, or
// inject it ourselves.
Object.assign(options, { allowNonTsExtensions: true });
const program = ts.createIncrementalProgram({
rootNames,
options,
host,
configFileParsingDiagnostics,
});
const { diagnostics: emitDiagnostics } = program.emit();
const diagnostics = [
...program.getConfigFileParsingDiagnostics(),
...program.getSyntacticDiagnostics(),
...program.getOptionsDiagnostics(),
...program.getGlobalDiagnostics(),
...program.getSemanticDiagnostics(),
...emitDiagnostics,
].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));
performanceProgram({ program });
core.jsonOpSync("op_respond", {
diagnostics: fromTypeScriptDiagnostic(diagnostics),
stats: performanceEnd(),
});
debug("<<< exec stop");
}
/**
* @param {number} id
* @param {any} data
*/
function respond(id, data = null) {
core.jsonOpSync("op_respond", { id, data });
}
/**
* @param {LanguageServerRequest} request
*/
function serverRequest({ id, ...request }) {
debug(`serverRequest()`, { id, ...request });
switch (request.method) {
case "configure": {
const { options, errors } = ts
.convertCompilerOptionsFromJson(request.compilerOptions, "");
Object.assign(options, { allowNonTsExtensions: true });
if (errors.length) {
debug(ts.formatDiagnostics(errors, host));
}
compilationSettings = options;
return respond(id, true);
}
case "getAsset": {
const sourceFile = host.getSourceFile(
request.specifier,
ts.ScriptTarget.ESNext,
);
return respond(id, sourceFile && sourceFile.text);
}
case "getDiagnostics": {
try {
/** @type {Record<string, any[]>} */
const diagnosticMap = {};
for (const specifier of request.specifiers) {
diagnosticMap[specifier] = fromTypeScriptDiagnostic([
...languageService.getSemanticDiagnostics(specifier),
...languageService.getSuggestionDiagnostics(specifier),
...languageService.getSyntacticDiagnostics(specifier),
].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code)));
}
return respond(id, diagnosticMap);
} catch (e) {
if ("stack" in e) {
error(e.stack);
} else {
error(e);
}
return respond(id, {});
}
}
case "getQuickInfo": {
return respond(
id,
languageService.getQuickInfoAtPosition(
request.specifier,
request.position,
),
);
}
case "getCompletions": {
return respond(
id,
languageService.getCompletionsAtPosition(
request.specifier,
request.position,
request.preferences,
),
);
}
case "getDocumentHighlights": {
return respond(
id,
languageService.getDocumentHighlights(
request.specifier,
request.position,
request.filesToSearch,
),
);
}
case "getReferences": {
return respond(
id,
languageService.getReferencesAtPosition(
request.specifier,
request.position,
),
);
}
case "getDefinition": {
return respond(
id,
languageService.getDefinitionAndBoundSpan(
request.specifier,
request.position,
),
);
}
case "getImplementation": {
return respond(
id,
languageService.getImplementationAtPosition(
request.specifier,
request.position,
),
);
}
case "findRenameLocations": {
return respond(
id,
languageService.findRenameLocations(
request.specifier,
request.position,
request.findInStrings,
request.findInComments,
request.providePrefixAndSuffixTextForRename,
),
);
}
default:
throw new TypeError(
// @ts-ignore exhausted case statement sets type to never
`Invalid request method for request: "${request.method}" (${id})`,
);
}
}
/** @param {{ debug: boolean; }} init */
function serverInit({ debug: debugFlag }) {
if (hasStarted) {
throw new Error("The language server has already been initialized.");
}
hasStarted = true;
languageService = ts.createLanguageService(host);
core.ops();
setLogDebug(debugFlag, "TSLS");
debug("serverInit()");
}
let hasStarted = false;
/** Startup the runtime environment, setting various flags.
* @param {{ debugFlag?: boolean; legacyFlag?: boolean; }} msg
*/
function startup({ debugFlag = false }) {
if (hasStarted) {
throw new Error("The compiler runtime already started.");
}
hasStarted = true;
core.ops();
setLogDebug(!!debugFlag, "TS");
}
// Setup the compiler runtime during the build process.
core.ops();
core.registerErrorClass("Error", Error);
// A build time only op that provides some setup information that is used to
// ensure the snapshot is setup properly.
/** @type {{ buildSpecifier: string; libs: string[] }} */
const { buildSpecifier, libs } = core.jsonOpSync("op_build_info", {});
for (const lib of libs) {
const specifier = `lib.${lib}.d.ts`;
// we are using internal APIs here to "inject" our custom libraries into
// tsc, so things like `"lib": [ "deno.ns" ]` are supported.
if (!ts.libs.includes(lib)) {
ts.libs.push(lib);
ts.libMap.set(lib, `lib.${lib}.d.ts`);
}
// we are caching in memory common type libraries that will be re-used by
// tsc on when the snapshot is restored
assert(
host.getSourceFile(`${ASSETS}${specifier}`, ts.ScriptTarget.ESNext),
);
}
// this helps ensure as much as possible is in memory that is re-usable
// before the snapshotting is done, which helps unsure fast "startup" for
// subsequent uses of tsc in Deno.
const TS_SNAPSHOT_PROGRAM = ts.createProgram({
rootNames: [buildSpecifier],
options: SNAPSHOT_COMPILE_OPTIONS,
host,
});
ts.getPreEmitDiagnostics(TS_SNAPSHOT_PROGRAM);
// exposes the two functions that are called by `tsc::exec()` when type
// checking TypeScript.
globalThis.startup = startup;
globalThis.exec = exec;
// exposes the functions that are called when the compiler is used as a
// language service.
globalThis.serverInit = serverInit;
globalThis.serverRequest = serverRequest;
})(this);

View file

@ -1,5 +0,0 @@
{
"compilerOptions": {
"lib": ["deno.ns", "deno.unstable", "dom"]
}
}

View file

@ -1,28 +0,0 @@
{
"item": {
"name": "baz",
"kind": 6,
"detail": "Bar",
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 7,
"character": 3
}
},
"selectionRange": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 5,
"character": 5
}
}
}
}

View file

@ -1,42 +0,0 @@
[
{
"to": {
"name": "foo",
"kind": 12,
"detail": "",
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 2,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 0,
"character": 9
},
"end": {
"line": 0,
"character": 12
}
}
},
"fromRanges": [
{
"start": {
"line": 6,
"character": 11
},
"end": {
"line": 6,
"character": 14
}
}
]
}
]

View file

@ -1,28 +0,0 @@
[
{
"name": "baz",
"kind": 6,
"detail": "Bar",
"uri": "file:///a/file.ts",
"range": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 7,
"character": 3
}
},
"selectionRange": {
"start": {
"line": 5,
"character": 2
},
"end": {
"line": 5,
"character": 5
}
}
}
]

View file

@ -1,38 +0,0 @@
{
"documentChanges": [
{
"textDocument": {
"uri": "file:///a/file.ts",
"version": 1
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 0,
"character": 12
}
},
"newText": "variable_modified"
},
{
"range": {
"start": {
"line": 1,
"character": 12
},
"end": {
"line": 1,
"character": 20
}
},
"newText": "variable_modified"
}
]
}
]
}

View file

@ -1,98 +0,0 @@
[
{
"range": {
"start": {
"line": 2,
"character": 8
},
"end": {
"line": 2,
"character": 9
}
},
"parent": {
"range": {
"start": {
"line": 2,
"character": 8
},
"end": {
"line": 2,
"character": 15
}
},
"parent": {
"range": {
"start": {
"line": 2,
"character": 4
},
"end": {
"line": 4,
"character": 5
}
},
"parent": {
"range": {
"start": {
"line": 1,
"character": 13
},
"end": {
"line": 6,
"character": 2
}
},
"parent": {
"range": {
"start": {
"line": 1,
"character": 12
},
"end": {
"line": 6,
"character": 3
}
},
"parent": {
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 6,
"character": 3
}
},
"parent": {
"range": {
"start": {
"line": 0,
"character": 11
},
"end": {
"line": 7,
"character": 0
}
},
"parent": {
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 7,
"character": 1
}
}
}
}
}
}
}
}
}
}
]

View file

@ -23,6 +23,7 @@ flate2.workspace = true
futures.workspace = true
hyper = { workspace = true, features = ["server", "http1", "http2", "runtime"] }
lazy_static = "1.4.0"
lsp-types.workspace = true
once_cell.workspace = true
os_pipe.workspace = true
parking_lot.workspace = true

View file

@ -18,6 +18,7 @@ use crate::copy_dir_recursive;
use crate::deno_exe_path;
use crate::env_vars_for_npm_tests_no_sync_download;
use crate::http_server;
use crate::lsp::LspClientBuilder;
use crate::new_deno_dir;
use crate::strip_ansi_codes;
use crate::testdata_path;
@ -35,6 +36,7 @@ pub struct TestContextBuilder {
copy_temp_dir: Option<String>,
cwd: Option<String>,
envs: HashMap<String, String>,
deno_exe: Option<PathBuf>,
}
impl TestContextBuilder {
@ -110,7 +112,7 @@ impl TestContextBuilder {
testdata_path()
};
let deno_exe = deno_exe_path();
let deno_exe = self.deno_exe.clone().unwrap_or_else(deno_exe_path);
println!("deno_exe path {}", deno_exe.display());
let http_server_guard = if self.use_http_server {
@ -121,6 +123,7 @@ impl TestContextBuilder {
TestContext {
cwd: self.cwd.clone(),
deno_exe,
envs: self.envs.clone(),
use_temp_cwd: self.use_temp_cwd,
_http_server_guard: http_server_guard,
@ -132,6 +135,7 @@ impl TestContextBuilder {
#[derive(Clone)]
pub struct TestContext {
deno_exe: PathBuf,
envs: HashMap<String, String>,
use_temp_cwd: bool,
cwd: Option<String>,
@ -161,7 +165,7 @@ impl TestContext {
pub fn new_command(&self) -> TestCommandBuilder {
TestCommandBuilder {
command_name: Default::default(),
command_name: self.deno_exe.to_string_lossy().to_string(),
args: Default::default(),
args_vec: Default::default(),
stdin: Default::default(),
@ -172,10 +176,16 @@ impl TestContext {
context: self.clone(),
}
}
pub fn new_lsp_command(&self) -> LspClientBuilder {
let mut builder = LspClientBuilder::new();
builder.deno_exe(&self.deno_exe).set_test_context(self);
builder
}
}
pub struct TestCommandBuilder {
command_name: Option<String>,
command_name: String,
args: String,
args_vec: Vec<String>,
stdin: Option<String>,
@ -188,7 +198,7 @@ pub struct TestCommandBuilder {
impl TestCommandBuilder {
pub fn command_name(&mut self, name: impl AsRef<str>) -> &mut Self {
self.command_name = Some(name.as_ref().to_string());
self.command_name = name.as_ref().to_string();
self
}
@ -284,15 +294,11 @@ impl TestCommandBuilder {
arg.replace("$TESTDATA", &self.context.testdata_dir.to_string_lossy())
})
.collect::<Vec<_>>();
let command_name = self
.command_name
.as_ref()
.cloned()
.unwrap_or("deno".to_string());
let command_name = &self.command_name;
let mut command = if command_name == "deno" {
Command::new(deno_exe_path())
} else {
Command::new(&command_name)
Command::new(command_name)
};
command.env("DENO_DIR", self.context.deno_dir.path());

View file

@ -1,12 +1,29 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::deno_exe_path;
use crate::npm_registry_url;
use crate::TestContext;
use crate::TestContextBuilder;
use super::new_deno_dir;
use super::TempDir;
use anyhow::Result;
use lazy_static::lazy_static;
use lsp_types::ClientCapabilities;
use lsp_types::ClientInfo;
use lsp_types::CodeActionCapabilityResolveSupport;
use lsp_types::CodeActionClientCapabilities;
use lsp_types::CodeActionKindLiteralSupport;
use lsp_types::CodeActionLiteralSupport;
use lsp_types::CompletionClientCapabilities;
use lsp_types::CompletionItemCapability;
use lsp_types::FoldingRangeClientCapabilities;
use lsp_types::InitializeParams;
use lsp_types::TextDocumentClientCapabilities;
use lsp_types::TextDocumentSyncClientCapabilities;
use lsp_types::Url;
use lsp_types::WorkspaceClientCapabilities;
use parking_lot::Condvar;
use parking_lot::Mutex;
use regex::Regex;
@ -19,6 +36,7 @@ use serde_json::Value;
use std::io;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use std::process::Child;
use std::process::ChildStdin;
use std::process::ChildStdout;
@ -153,6 +171,335 @@ impl LspStdoutReader {
}
}
pub struct InitializeParamsBuilder {
params: InitializeParams,
}
impl InitializeParamsBuilder {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
params: InitializeParams {
process_id: None,
client_info: Some(ClientInfo {
name: "test-harness".to_string(),
version: Some("1.0.0".to_string()),
}),
root_uri: None,
initialization_options: Some(json!({
"enable": true,
"cache": null,
"certificateStores": null,
"codeLens": {
"implementations": true,
"references": true,
"test": true
},
"config": null,
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"testing": {
"args": [
"--allow-all"
],
"enable": true
},
"tlsCertificate": null,
"unsafelyIgnoreCertificateErrors": null,
"unstable": false
})),
capabilities: ClientCapabilities {
text_document: Some(TextDocumentClientCapabilities {
code_action: Some(CodeActionClientCapabilities {
code_action_literal_support: Some(CodeActionLiteralSupport {
code_action_kind: CodeActionKindLiteralSupport {
value_set: vec![
"quickfix".to_string(),
"refactor".to_string(),
],
},
}),
is_preferred_support: Some(true),
data_support: Some(true),
disabled_support: Some(true),
resolve_support: Some(CodeActionCapabilityResolveSupport {
properties: vec!["edit".to_string()],
}),
..Default::default()
}),
completion: Some(CompletionClientCapabilities {
completion_item: Some(CompletionItemCapability {
snippet_support: Some(true),
..Default::default()
}),
..Default::default()
}),
folding_range: Some(FoldingRangeClientCapabilities {
line_folding_only: Some(true),
..Default::default()
}),
synchronization: Some(TextDocumentSyncClientCapabilities {
dynamic_registration: Some(true),
will_save: Some(true),
will_save_wait_until: Some(true),
did_save: Some(true),
}),
..Default::default()
}),
workspace: Some(WorkspaceClientCapabilities {
configuration: Some(true),
workspace_folders: Some(true),
..Default::default()
}),
experimental: Some(json!({
"testingApi": true
})),
..Default::default()
},
..Default::default()
},
}
}
pub fn set_maybe_root_uri(&mut self, value: Option<Url>) -> &mut Self {
self.params.root_uri = value;
self
}
pub fn set_root_uri(&mut self, value: Url) -> &mut Self {
self.set_maybe_root_uri(Some(value))
}
pub fn set_workspace_folders(
&mut self,
folders: Vec<lsp_types::WorkspaceFolder>,
) -> &mut Self {
self.params.workspace_folders = Some(folders);
self
}
pub fn enable_inlay_hints(&mut self) -> &mut Self {
let options = self.initialization_options_mut();
options.insert(
"inlayHints".to_string(),
json!({
"parameterNames": {
"enabled": "all"
},
"parameterTypes": {
"enabled": true
},
"variableTypes": {
"enabled": true
},
"propertyDeclarationTypes": {
"enabled": true
},
"functionLikeReturnTypes": {
"enabled": true
},
"enumMemberValues": {
"enabled": true
}
}),
);
self
}
pub fn disable_testing_api(&mut self) -> &mut Self {
let obj = self
.params
.capabilities
.experimental
.as_mut()
.unwrap()
.as_object_mut()
.unwrap();
obj.insert("testingApi".to_string(), false.into());
let options = self.initialization_options_mut();
options.remove("testing");
self
}
pub fn set_cache(&mut self, value: impl AsRef<str>) -> &mut Self {
let options = self.initialization_options_mut();
options.insert("cache".to_string(), value.as_ref().to_string().into());
self
}
pub fn set_code_lens(
&mut self,
value: Option<serde_json::Value>,
) -> &mut Self {
let options = self.initialization_options_mut();
if let Some(value) = value {
options.insert("codeLens".to_string(), value);
} else {
options.remove("codeLens");
}
self
}
pub fn set_config(&mut self, value: impl AsRef<str>) -> &mut Self {
let options = self.initialization_options_mut();
options.insert("config".to_string(), value.as_ref().to_string().into());
self
}
pub fn set_enable_paths(&mut self, value: Vec<String>) -> &mut Self {
let options = self.initialization_options_mut();
options.insert("enablePaths".to_string(), value.into());
self
}
pub fn set_deno_enable(&mut self, value: bool) -> &mut Self {
let options = self.initialization_options_mut();
options.insert("enable".to_string(), value.into());
self
}
pub fn set_import_map(&mut self, value: impl AsRef<str>) -> &mut Self {
let options = self.initialization_options_mut();
options.insert("importMap".to_string(), value.as_ref().to_string().into());
self
}
pub fn set_tls_certificate(&mut self, value: impl AsRef<str>) -> &mut Self {
let options = self.initialization_options_mut();
options.insert(
"tlsCertificate".to_string(),
value.as_ref().to_string().into(),
);
self
}
pub fn set_unstable(&mut self, value: bool) -> &mut Self {
let options = self.initialization_options_mut();
options.insert("unstable".to_string(), value.into());
self
}
pub fn add_test_server_suggestions(&mut self) -> &mut Self {
self.set_suggest_imports_hosts(vec![(
"http://localhost:4545/".to_string(),
true,
)])
}
pub fn set_suggest_imports_hosts(
&mut self,
values: Vec<(String, bool)>,
) -> &mut Self {
let options = self.initialization_options_mut();
let suggest = options.get_mut("suggest").unwrap().as_object_mut().unwrap();
let imports = suggest.get_mut("imports").unwrap().as_object_mut().unwrap();
let hosts = imports.get_mut("hosts").unwrap().as_object_mut().unwrap();
hosts.clear();
for (key, value) in values {
hosts.insert(key, value.into());
}
self
}
pub fn with_capabilities(
&mut self,
mut action: impl FnMut(&mut ClientCapabilities),
) -> &mut Self {
action(&mut self.params.capabilities);
self
}
fn initialization_options_mut(
&mut self,
) -> &mut serde_json::Map<String, serde_json::Value> {
let options = self.params.initialization_options.as_mut().unwrap();
options.as_object_mut().unwrap()
}
pub fn build(&self) -> InitializeParams {
self.params.clone()
}
}
pub struct LspClientBuilder {
print_stderr: bool,
deno_exe: PathBuf,
context: Option<TestContext>,
}
impl LspClientBuilder {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
print_stderr: false,
deno_exe: deno_exe_path(),
context: None,
}
}
pub fn deno_exe(&mut self, exe_path: impl AsRef<Path>) -> &mut Self {
self.deno_exe = exe_path.as_ref().to_path_buf();
self
}
pub fn print_stderr(&mut self) -> &mut Self {
self.print_stderr = true;
self
}
pub fn set_test_context(&mut self, test_context: &TestContext) -> &mut Self {
self.context = Some(test_context.clone());
self
}
pub fn build(&self) -> LspClient {
self.build_result().unwrap()
}
pub fn build_result(&self) -> Result<LspClient> {
let deno_dir = new_deno_dir();
let mut command = Command::new(&self.deno_exe);
command
.env("DENO_DIR", deno_dir.path())
.env("NPM_CONFIG_REGISTRY", npm_registry_url())
.arg("lsp")
.stdin(Stdio::piped())
.stdout(Stdio::piped());
if !self.print_stderr {
command.stderr(Stdio::null());
}
let mut child = command.spawn()?;
let stdout = child.stdout.take().unwrap();
let buf_reader = io::BufReader::new(stdout);
let reader = LspStdoutReader::new(buf_reader);
let stdin = child.stdin.take().unwrap();
let writer = io::BufWriter::new(stdin);
Ok(LspClient {
child,
reader,
request_id: 1,
start: Instant::now(),
context: self
.context
.clone()
.unwrap_or_else(|| TestContextBuilder::new().build()),
writer,
deno_dir,
})
}
}
pub struct LspClient {
child: Child,
reader: LspStdoutReader,
@ -160,6 +507,7 @@ pub struct LspClient {
start: Instant,
writer: io::BufWriter<ChildStdin>,
deno_dir: TempDir,
context: TestContext,
}
impl Drop for LspClient {
@ -228,36 +576,6 @@ where
}
impl LspClient {
pub fn new(deno_exe: &Path, print_stderr: bool) -> Result<Self> {
let deno_dir = new_deno_dir();
let mut command = Command::new(deno_exe);
command
.env("DENO_DIR", deno_dir.path())
.env("NPM_CONFIG_REGISTRY", npm_registry_url())
.arg("lsp")
.stdin(Stdio::piped())
.stdout(Stdio::piped());
if !print_stderr {
command.stderr(Stdio::null());
}
let mut child = command.spawn()?;
let stdout = child.stdout.take().unwrap();
let buf_reader = io::BufReader::new(stdout);
let reader = LspStdoutReader::new(buf_reader);
let stdin = child.stdin.take().unwrap();
let writer = io::BufWriter::new(stdin);
Ok(Self {
child,
reader,
request_id: 1,
start: Instant::now(),
writer,
deno_dir,
})
}
pub fn deno_dir(&self) -> &TempDir {
&self.deno_dir
}
@ -274,6 +592,30 @@ impl LspClient {
self.reader.pending_len()
}
pub fn initialize_default(&mut self) {
self.initialize(|_| {})
}
pub fn initialize(
&mut self,
do_build: impl Fn(&mut InitializeParamsBuilder),
) {
let mut builder = InitializeParamsBuilder::new();
builder.set_root_uri(self.context.deno_dir().uri());
do_build(&mut builder);
self
.write_request::<_, _, Value>("initialize", builder.build())
.unwrap();
self.write_notification("initialized", json!({})).unwrap();
}
pub fn shutdown(&mut self) {
self
.write_request::<_, _, Value>("shutdown", json!(null))
.unwrap();
self.write_notification("exit", json!(null)).unwrap();
}
// it's flaky to assert for a notification because a notification
// might arrive a little later, so only provide a method for asserting
// that there is no notification

View file

@ -9,6 +9,7 @@ use std::sync::Arc;
use std::time::SystemTime;
use anyhow::Context;
use lsp_types::Url;
use once_cell::sync::OnceCell;
static TEMP_DIR_SESSION: OnceCell<TempDirSession> = OnceCell::new();
@ -83,6 +84,10 @@ impl TempDir {
})
}
pub fn uri(&self) -> Url {
Url::from_directory_path(self.path()).unwrap()
}
pub fn path(&self) -> &Path {
let inner = &self.0;
inner.0.as_path()