Skip to content

Commit

Permalink
refactor(lsp): store language sections in WorkspaceSettings (denoland…
Browse files Browse the repository at this point in the history
…#20593)

When sending configuration requests to the client, reads `javascript`
and `typescript` sections in addition to `deno`.

The LSP's initialization options now accepts `javascript` and
`typescript` namespaces.
  • Loading branch information
nayeemrmn authored Sep 21, 2023
1 parent 0981aef commit a4ac6a3
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 185 deletions.
51 changes: 37 additions & 14 deletions cli/lsp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use deno_core::anyhow::anyhow;
use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::Value;
use deno_core::unsync::spawn;
use tower_lsp::lsp_types as lsp;
use tower_lsp::lsp_types::ConfigurationItem;

use crate::lsp::repl::get_repl_workspace_settings;

use super::config::SpecifierSettings;
use super::config::WorkspaceSettings;
use super::config::SETTINGS_SECTION;
use super::lsp_custom;
use super::testing::lsp_custom as testing_lsp_custom;
Expand Down Expand Up @@ -148,7 +148,9 @@ impl OutsideLockClient {
}
}

pub async fn workspace_configuration(&self) -> Result<Value, AnyError> {
pub async fn workspace_configuration(
&self,
) -> Result<WorkspaceSettings, AnyError> {
self.0.workspace_configuration().await
}

Expand Down Expand Up @@ -186,7 +188,9 @@ trait ClientTrait: Send + Sync {
&self,
uris: Vec<lsp::Url>,
) -> Result<Vec<Result<SpecifierSettings, AnyError>>, AnyError>;
async fn workspace_configuration(&self) -> Result<Value, AnyError>;
async fn workspace_configuration(
&self,
) -> Result<WorkspaceSettings, AnyError>;
async fn show_message(&self, message_type: lsp::MessageType, text: String);
async fn register_capability(
&self,
Expand Down Expand Up @@ -284,19 +288,36 @@ impl ClientTrait for TowerClient {
)
}

async fn workspace_configuration(&self) -> Result<Value, AnyError> {
async fn workspace_configuration(
&self,
) -> Result<WorkspaceSettings, AnyError> {
let config_response = self
.0
.configuration(vec![ConfigurationItem {
scope_uri: None,
section: Some(SETTINGS_SECTION.to_string()),
}])
.configuration(vec![
ConfigurationItem {
scope_uri: None,
section: Some(SETTINGS_SECTION.to_string()),
},
ConfigurationItem {
scope_uri: None,
section: Some("javascript".to_string()),
},
ConfigurationItem {
scope_uri: None,
section: Some("typescript".to_string()),
},
])
.await;
match config_response {
Ok(value_vec) => match value_vec.get(0).cloned() {
Some(value) => Ok(value),
None => bail!("Missing response workspace configuration."),
},
Ok(configs) => {
let mut configs = configs.into_iter();
let deno = serde_json::to_value(configs.next()).unwrap();
let javascript = serde_json::to_value(configs.next()).unwrap();
let typescript = serde_json::to_value(configs.next()).unwrap();
Ok(WorkspaceSettings::from_raw_settings(
deno, javascript, typescript,
))
}
Err(err) => {
bail!("Error getting workspace configuration: {}", err)
}
Expand Down Expand Up @@ -367,8 +388,10 @@ impl ClientTrait for ReplClient {
Ok(settings)
}

async fn workspace_configuration(&self) -> Result<Value, AnyError> {
Ok(serde_json::to_value(get_repl_workspace_settings()).unwrap())
async fn workspace_configuration(
&self,
) -> Result<WorkspaceSettings, AnyError> {
Ok(get_repl_workspace_settings())
}

async fn show_message(
Expand Down
Loading

0 comments on commit a4ac6a3

Please sign in to comment.