Skip to content

Commit

Permalink
refactor(lsp): add "deno.reloadImportRegistries" as a command (denola…
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Oct 10, 2023
1 parent 2665ca1 commit 6bbccb7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cli/lsp/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ pub fn server_capabilities(
color_provider: None,
execute_command_provider: Some(ExecuteCommandOptions {
commands: if enable_builtin_commands {
vec!["deno.cache".into()]
vec![
"deno.cache".to_string(),
"deno.reloadImportRegistries".to_string(),
]
} else {
vec![]
},
Expand Down
9 changes: 6 additions & 3 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
let referrer = serde_json::to_value(arguments.next()).unwrap();
let referrer: Url = serde_json::from_value(referrer)
.map_err(|err| LspError::invalid_params(err.to_string()))?;
return self
self
.cache_request(Some(
serde_json::to_value(lsp_custom::CacheParams {
referrer: TextDocumentIdentifier { uri: referrer },
Expand All @@ -3046,9 +3046,12 @@ impl tower_lsp::LanguageServer for LanguageServer {
})
.expect("well formed json"),
))
.await;
.await
} else if params.command == "deno.reloadImportRegistries" {
self.0.write().await.reload_import_registries().await
} else {
Ok(None)
}
Ok(None)
}

async fn initialize(
Expand Down
3 changes: 3 additions & 0 deletions cli/lsp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub async fn start() -> Result<(), AnyError> {
lsp_custom::PERFORMANCE_REQUEST,
LanguageServer::performance_request,
)
// TODO(nayeemrmn): The extension has replaced this with the
// `deno.reloadImportRegistries` command as of vscode_deno
// 3.26.0 / 2023.10.10. Remove this eventually.
.custom_method(
lsp_custom::RELOAD_IMPORT_REGISTRIES_REQUEST,
LanguageServer::reload_import_registries_request,
Expand Down
12 changes: 12 additions & 0 deletions cli/tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,18 @@ fn lsp_deno_task() {
);
}

#[test]
fn lsp_reload_import_registries_command() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let mut client = context.new_lsp_command().build();
client.initialize_default();
let res = client.write_request(
"workspace/executeCommand",
json!({ "command": "deno.reloadImportRegistries" }),
);
assert_eq!(res, json!(true));
}

#[test]
fn lsp_import_attributes() {
let context = TestContextBuilder::new().use_temp_cwd().build();
Expand Down

0 comments on commit 6bbccb7

Please sign in to comment.