mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -05:00
fix(lsp): support task object notation for tasks request (#27076)
This commit is contained in:
parent
594f59dc1d
commit
ec81cbbd86
4 changed files with 21 additions and 24 deletions
|
@ -3781,14 +3781,11 @@ impl Inner {
|
||||||
fn task_definitions(&self) -> LspResult<Vec<TaskDefinition>> {
|
fn task_definitions(&self) -> LspResult<Vec<TaskDefinition>> {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
for config_file in self.config.tree.config_files() {
|
for config_file in self.config.tree.config_files() {
|
||||||
if let Some(tasks) = json!(&config_file.json.tasks).as_object() {
|
if let Some(tasks) = config_file.to_tasks_config().ok().flatten() {
|
||||||
for (name, value) in tasks {
|
for (name, def) in tasks {
|
||||||
let Some(command) = value.as_str() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
result.push(TaskDefinition {
|
result.push(TaskDefinition {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
command: command.to_string(),
|
command: def.command.clone(),
|
||||||
source_uri: url_to_uri(&config_file.specifier)
|
source_uri: url_to_uri(&config_file.specifier)
|
||||||
.map_err(|_| LspError::internal_error())?,
|
.map_err(|_| LspError::internal_error())?,
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,8 +14,6 @@ pub const LATEST_DIAGNOSTIC_BATCH_INDEX: &str =
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct TaskDefinition {
|
pub struct TaskDefinition {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
// TODO(nayeemrmn): Rename this to `command` in vscode_deno.
|
|
||||||
#[serde(rename = "detail")]
|
|
||||||
pub command: String,
|
pub command: String,
|
||||||
pub source_uri: lsp::Uri,
|
pub source_uri: lsp::Uri,
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,9 +56,6 @@ pub async fn start() -> Result<(), AnyError> {
|
||||||
LanguageServer::performance_request,
|
LanguageServer::performance_request,
|
||||||
)
|
)
|
||||||
.custom_method(lsp_custom::TASK_REQUEST, LanguageServer::task_definitions)
|
.custom_method(lsp_custom::TASK_REQUEST, LanguageServer::task_definitions)
|
||||||
// TODO(nayeemrmn): Rename this to `deno/taskDefinitions` in vscode_deno and
|
|
||||||
// remove this alias.
|
|
||||||
.custom_method("deno/task", LanguageServer::task_definitions)
|
|
||||||
.custom_method(testing::TEST_RUN_REQUEST, LanguageServer::test_run_request)
|
.custom_method(testing::TEST_RUN_REQUEST, LanguageServer::test_run_request)
|
||||||
.custom_method(
|
.custom_method(
|
||||||
testing::TEST_RUN_CANCEL_REQUEST,
|
testing::TEST_RUN_CANCEL_REQUEST,
|
||||||
|
|
|
@ -1360,26 +1360,31 @@ fn lsp_deno_task() {
|
||||||
let temp_dir = context.temp_dir();
|
let temp_dir = context.temp_dir();
|
||||||
temp_dir.write(
|
temp_dir.write(
|
||||||
"deno.jsonc",
|
"deno.jsonc",
|
||||||
r#"{
|
json!({
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"build": "deno test"
|
"build": "deno test",
|
||||||
}
|
"serve": {
|
||||||
}"#,
|
"description": "Start the dev server",
|
||||||
|
"command": "deno run -RN server.ts",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut client = context.new_lsp_command().build();
|
let mut client = context.new_lsp_command().build();
|
||||||
client.initialize(|builder| {
|
client.initialize_default();
|
||||||
builder.set_config("./deno.jsonc");
|
let res = client.write_request("deno/taskDefinitions", json!(null));
|
||||||
});
|
|
||||||
|
|
||||||
let res = client.write_request("deno/task", json!(null));
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
json!([
|
json!([
|
||||||
{
|
{
|
||||||
"name": "build",
|
"name": "build",
|
||||||
"detail": "deno test",
|
"command": "deno test",
|
||||||
|
"sourceUri": temp_dir.url().join("deno.jsonc").unwrap(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "serve",
|
||||||
|
"command": "deno run -RN server.ts",
|
||||||
"sourceUri": temp_dir.url().join("deno.jsonc").unwrap(),
|
"sourceUri": temp_dir.url().join("deno.jsonc").unwrap(),
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in a new issue