summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2022-03-21 12:33:37 +1100
committerGitHub <noreply@github.com>2022-03-21 12:33:37 +1100
commit1414dc503ba4cddcc5fdd5a0417d54678b1ac3fb (patch)
tree5aa4a03505c3c64d1624bca6417a47c84a97b6fd /cli/tests
parentdaa7c6d32ab5a4029f8084e174d621f5562256be (diff)
feat(lsp): support deno.enablePaths setting (#13978)
Ref: denoland/vscode_deno#633
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/lsp_tests.rs248
-rw-r--r--cli/tests/testdata/lsp/initialize_params_workspace_enable_paths.json77
2 files changed, 307 insertions, 18 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 5547dc214..90fbd608d 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -57,24 +57,22 @@ where
.write_notification("textDocument/didOpen", params)
.unwrap();
- handle_configuration_request(client);
+ handle_configuration_request(
+ client,
+ json!([{
+ "enable": true,
+ "codeLens": {
+ "test": true
+ }
+ }]),
+ );
read_diagnostics(client).0
}
-fn handle_configuration_request(client: &mut LspClient) {
+fn handle_configuration_request(client: &mut LspClient, result: Value) {
let (id, method, _) = client.read_request::<Value>().unwrap();
assert_eq!(method, "workspace/configuration");
- client
- .write_response(
- id,
- json!([{
- "enable": true,
- "codeLens": {
- "test": true
- }
- }]),
- )
- .unwrap();
+ client.write_response(id, result).unwrap();
}
fn read_diagnostics(client: &mut LspClient) -> CollectedDiagnostics {
@@ -97,6 +95,17 @@ fn shutdown(client: &mut LspClient) {
client.write_notification("exit", json!(null)).unwrap();
}
+pub fn ensure_directory_specifier(
+ mut specifier: ModuleSpecifier,
+) -> ModuleSpecifier {
+ let path = specifier.path();
+ if !path.ends_with('/') {
+ let new_path = format!("{}/", path);
+ specifier.set_path(&new_path);
+ }
+ specifier
+}
+
struct TestSession {
client: LspClient,
open_file_count: usize,
@@ -586,7 +595,15 @@ fn lsp_import_assertions() {
}),
)
.unwrap();
- handle_configuration_request(&mut client);
+ handle_configuration_request(
+ &mut client,
+ json!([{
+ "enable": true,
+ "codeLens": {
+ "test": true
+ }
+ }]),
+ );
let diagnostics = CollectedDiagnostics(did_open(
&mut client,
@@ -981,18 +998,136 @@ fn lsp_hover_disabled() {
)
.unwrap();
- let (id, method, _) = client.read_request::<Value>().unwrap();
- assert_eq!(method, "workspace/configuration");
+ handle_configuration_request(&mut client, json!([{ "enable": false }]));
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts"
+ },
+ "position": {
+ "line": 0,
+ "character": 19
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(maybe_res, Some(json!(null)));
+ shutdown(&mut client);
+}
+
+#[test]
+fn lsp_workspace_enable_paths() {
+ let mut params: lsp::InitializeParams = serde_json::from_value(load_fixture(
+ "initialize_params_workspace_enable_paths.json",
+ ))
+ .unwrap();
+ // we aren't actually writing anything to the tempdir in this test, but we
+ // just need a legitimate file path on the host system so that logic that
+ // tries to convert to and from the fs paths works on all env
+ let temp_dir = TempDir::new().unwrap();
+
+ let root_specifier =
+ ensure_directory_specifier(Url::from_file_path(temp_dir.path()).unwrap());
+
+ params.root_uri = Some(root_specifier.clone());
+ params.workspace_folders = Some(vec![lsp::WorkspaceFolder {
+ uri: root_specifier.clone(),
+ name: "project".to_string(),
+ }]);
+
+ let deno_exe = deno_exe_path();
+ let mut client = LspClient::new(&deno_exe).unwrap();
client
- .write_response(id, json!([{ "enable": false }]))
+ .write_request::<_, _, Value>("initialize", params)
.unwrap();
+ client.write_notification("initialized", json!({})).unwrap();
+
+ handle_configuration_request(
+ &mut client,
+ json!([{
+ "enable": false,
+ "enablePaths": [
+ "./worker"
+ ],
+ }]),
+ );
+
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "console.log(Date.now());\n"
+ }
+ }),
+ );
+
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./other/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "console.log(Date.now());\n"
+ }
+ }),
+ );
+
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./worker/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "console.log(Date.now());\n"
+ }
+ }),
+ );
+
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "console.log(Date.now());\n"
+ }
+ }),
+ );
+
let (maybe_res, maybe_err) = client
.write_request(
"textDocument/hover",
json!({
"textDocument": {
- "uri": "file:///a/file.ts"
+ "uri": root_specifier.join("./file.ts").unwrap(),
+ },
+ "position": {
+ "line": 0,
+ "character": 19
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(maybe_res, Some(json!(null)));
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./other/file.ts").unwrap(),
},
"position": {
"line": 0,
@@ -1003,6 +1138,83 @@ fn lsp_hover_disabled() {
.unwrap();
assert!(maybe_err.is_none());
assert_eq!(maybe_res, Some(json!(null)));
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./worker/file.ts").unwrap(),
+ },
+ "position": {
+ "line": 0,
+ "character": 19
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(json!({
+ "contents": [
+ {
+ "language": "typescript",
+ "value": "(method) DateConstructor.now(): number",
+ },
+ ""
+ ],
+ "range": {
+ "start": {
+ "line": 0,
+ "character": 17,
+ },
+ "end": {
+ "line": 0,
+ "character": 20,
+ }
+ }
+ }))
+ );
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
+ },
+ "position": {
+ "line": 0,
+ "character": 19
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(json!({
+ "contents": [
+ {
+ "language": "typescript",
+ "value": "(method) DateConstructor.now(): number",
+ },
+ ""
+ ],
+ "range": {
+ "start": {
+ "line": 0,
+ "character": 17,
+ },
+ "end": {
+ "line": 0,
+ "character": 20,
+ }
+ }
+ }))
+ );
+
shutdown(&mut client);
}
diff --git a/cli/tests/testdata/lsp/initialize_params_workspace_enable_paths.json b/cli/tests/testdata/lsp/initialize_params_workspace_enable_paths.json
new file mode 100644
index 000000000..87581ebd7
--- /dev/null
+++ b/cli/tests/testdata/lsp/initialize_params_workspace_enable_paths.json
@@ -0,0 +1,77 @@
+{
+ "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
+ }
+ }
+}