summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2022-03-29 11:27:43 +1100
committerGitHub <noreply@github.com>2022-03-29 11:27:43 +1100
commit5a6a1eeb3918985ab003fd8d87faebb76410a242 (patch)
tree9602da13a8b81d0742eecb71063b4fab9e5eb099
parent89dd5dac6219f9a4c04ada4b5a9c812a88c1c2d4 (diff)
feat(lsp): support API for config file (#14139)
Closes: #13910
-rw-r--r--cli/config_file.rs19
-rw-r--r--cli/lsp/capabilities.rs32
-rw-r--r--cli/lsp/language_server.rs10
-rw-r--r--cli/lsp/lsp_custom.rs1
-rw-r--r--cli/tests/integration/lsp_tests.rs45
5 files changed, 80 insertions, 27 deletions
diff --git a/cli/config_file.rs b/cli/config_file.rs
index 156350064..2c1ec7907 100644
--- a/cli/config_file.rs
+++ b/cli/config_file.rs
@@ -649,6 +649,25 @@ impl ConfigFile {
}
}
+ /// Return any tasks that are defined in the configuration file as a sequence
+ /// of JSON objects providing the name of the task and the arguments of the
+ /// task in a detail field.
+ pub fn to_lsp_tasks(&self) -> Option<Value> {
+ let value = self.json.tasks.clone()?;
+ let tasks: BTreeMap<String, String> = serde_json::from_value(value).ok()?;
+ Some(
+ tasks
+ .into_iter()
+ .map(|(key, value)| {
+ json!({
+ "name": key,
+ "detail": value,
+ })
+ })
+ .collect(),
+ )
+ }
+
pub fn to_tasks_config(
&self,
) -> Result<Option<BTreeMap<String, String>>, AnyError> {
diff --git a/cli/lsp/capabilities.rs b/cli/lsp/capabilities.rs
index 49adc961d..ed371bab1 100644
--- a/cli/lsp/capabilities.rs
+++ b/cli/lsp/capabilities.rs
@@ -5,32 +5,8 @@
///! language server, which helps determine what messages are sent from the
///! client.
///!
-use lspower::lsp::CallHierarchyServerCapability;
-use lspower::lsp::ClientCapabilities;
-use lspower::lsp::CodeActionKind;
-use lspower::lsp::CodeActionOptions;
-use lspower::lsp::CodeActionProviderCapability;
-use lspower::lsp::CodeLensOptions;
-use lspower::lsp::CompletionOptions;
-use lspower::lsp::DocumentSymbolOptions;
-use lspower::lsp::FoldingRangeProviderCapability;
-use lspower::lsp::HoverProviderCapability;
-use lspower::lsp::ImplementationProviderCapability;
-use lspower::lsp::OneOf;
-use lspower::lsp::SaveOptions;
-use lspower::lsp::SelectionRangeProviderCapability;
-use lspower::lsp::SemanticTokensFullOptions;
-use lspower::lsp::SemanticTokensOptions;
-use lspower::lsp::SemanticTokensServerCapabilities;
-use lspower::lsp::ServerCapabilities;
-use lspower::lsp::SignatureHelpOptions;
-use lspower::lsp::TextDocumentSyncCapability;
-use lspower::lsp::TextDocumentSyncKind;
-use lspower::lsp::TextDocumentSyncOptions;
-use lspower::lsp::TypeDefinitionProviderCapability;
-use lspower::lsp::WorkDoneProgressOptions;
-use lspower::lsp::WorkspaceFoldersServerCapabilities;
-use lspower::lsp::WorkspaceServerCapabilities;
+use deno_core::serde_json::json;
+use lspower::lsp::*;
use super::refactor::ALL_KNOWN_REFACTOR_ACTION_KINDS;
use super::semantic_tokens::get_legend;
@@ -158,8 +134,10 @@ pub fn server_capabilities(
}),
file_operations: None,
}),
- experimental: None,
linked_editing_range_provider: None,
moniker_provider: None,
+ experimental: Some(json!({
+ "denoConfigTasks": true,
+ })),
}
}
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index c2083bc48..1afcff8a6 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -2141,6 +2141,7 @@ impl Inner {
lsp_custom::RELOAD_IMPORT_REGISTRIES_REQUEST => {
self.reload_import_registries().await
}
+ lsp_custom::TASK_REQUEST => self.get_tasks(),
lsp_custom::VIRTUAL_TEXT_DOCUMENT => {
match params.map(serde_json::from_value) {
Some(Ok(params)) => Ok(Some(
@@ -2831,6 +2832,15 @@ impl Inner {
json!({ "averages": averages })
}
+ fn get_tasks(&self) -> LspResult<Option<Value>> {
+ Ok(
+ self
+ .maybe_config_file
+ .as_ref()
+ .and_then(|cf| cf.to_lsp_tasks()),
+ )
+ }
+
async fn reload_import_registries(&mut self) -> LspResult<Option<Value>> {
fs_util::remove_dir_all_if_exists(&self.module_registries_location)
.await
diff --git a/cli/lsp/lsp_custom.rs b/cli/lsp/lsp_custom.rs
index 1d8c20984..eff55e2ea 100644
--- a/cli/lsp/lsp_custom.rs
+++ b/cli/lsp/lsp_custom.rs
@@ -6,6 +6,7 @@ use lspower::lsp;
pub const CACHE_REQUEST: &str = "deno/cache";
pub const PERFORMANCE_REQUEST: &str = "deno/performance";
+pub const TASK_REQUEST: &str = "deno/task";
pub const RELOAD_IMPORT_REGISTRIES_REQUEST: &str =
"deno/reloadImportRegistries";
pub const VIRTUAL_TEXT_DOCUMENT: &str = "deno/virtualTextDocument";
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index b8f33ddcc..63695634a 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -580,6 +580,51 @@ fn lsp_import_map_config_file() {
}
#[test]
+fn lsp_deno_task() {
+ let temp_dir = TempDir::new().unwrap();
+ let workspace_root = temp_dir.path().canonicalize().unwrap();
+ let mut params: lsp::InitializeParams =
+ serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
+ fs::write(
+ workspace_root.join("deno.jsonc"),
+ r#"{
+ "tasks": {
+ "build": "deno test",
+ "some:test": "deno bundle mod.ts"
+ }
+ }"#,
+ )
+ .unwrap();
+
+ params.root_uri = Some(Url::from_file_path(workspace_root).unwrap());
+
+ let deno_exe = deno_exe_path();
+ let mut client = LspClient::new(&deno_exe).unwrap();
+ client
+ .write_request::<_, _, Value>("initialize", params)
+ .unwrap();
+
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, Value>("deno/task", json!({}))
+ .unwrap();
+
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(json!([
+ {
+ "name": "build",
+ "detail": "deno test"
+ },
+ {
+ "name": "some:test",
+ "detail": "deno bundle mod.ts"
+ }
+ ]))
+ );
+}
+
+#[test]
fn lsp_import_assertions() {
let mut client = init("initialize_params_import_map.json");
client