Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions crates/oxc_language_server/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ impl LanguageServer for Backend {
return Some(new_settings);
}

let deprecated_settings = value.get("settings");

// the client has deprecated settings and has a deprecated root uri.
// handle all things like the old way
if deprecated_settings.is_some() && params.root_uri.is_some() {
if let (Some(deprecated_settings), Some(root_uri)) =
(value.get("settings"), params.root_uri.as_ref())
{
return Some(vec![WorkspaceOption {
workspace_uri: params.root_uri.clone().unwrap(),
options: deprecated_settings.unwrap().clone(),
workspace_uri: root_uri.clone(),
options: deprecated_settings.clone(),
}]);
}

Expand Down Expand Up @@ -129,15 +129,14 @@ impl LanguageServer for Backend {
// start the linter. We do not start the linter when the client support the request,
// we will init the linter after requesting for the workspace configuration.
if !capabilities.workspace_configuration || options.is_some() {
let mut options = options.unwrap_or_default().into_iter();

for worker in &workers {
let option = options
.as_deref()
.unwrap_or_default()
.iter()
.find(|workspace_option| {
worker.is_responsible_for_uri(&workspace_option.workspace_uri)
})
.map(|workspace_options| workspace_options.options.clone())
.map(|workspace_options| workspace_options.options)
.unwrap_or_default();

worker.start_worker(option, &self.tool_builders).await;
Expand Down Expand Up @@ -522,7 +521,7 @@ impl LanguageServer for Backend {
let content = params.content_changes.first().map(|c| c.text.clone());

if let Some(content) = &content {
self.file_system.write().await.set(&uri, content.clone());
self.file_system.write().await.set(uri.clone(), content.clone());
}

if let Some(diagnostics) = worker.run_diagnostic_on_change(&uri, content.as_deref()).await {
Expand All @@ -545,7 +544,7 @@ impl LanguageServer for Backend {

let content = params.text_document.text;

self.file_system.write().await.set(&uri, content.clone());
self.file_system.write().await.set(uri.clone(), content.clone());

if let Some(diagnostics) = worker.run_diagnostic(&uri, Some(&content)).await {
self.client
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_language_server/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tower_lsp_server::lsp_types::{
WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities,
};

#[derive(Clone, Default)]
#[derive(Default)]
pub struct Capabilities {
pub workspace_apply_edit: bool,
pub workspace_configuration: bool,
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_language_server/src/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ impl LSPFileSystem {
self.files.pin().clear();
}

pub fn set(&self, uri: &Uri, content: String) {
self.files.pin().insert(uri.clone(), content);
pub fn set(&self, uri: Uri, content: String) {
self.files.pin().insert(uri, content);
}

pub fn get(&self, uri: &Uri) -> Option<String> {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl Tool for ServerLinter {
&self,
uri: &Uri,
range: &Range,
only_code_action_kinds: Option<Vec<CodeActionKind>>,
only_code_action_kinds: Option<&Vec<CodeActionKind>>,
) -> Vec<CodeActionOrCommand> {
let actions = self.get_code_actions_for_uri(uri);

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_language_server/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use tower_lsp_server::lsp_types::Uri;

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceOption {
pub workspace_uri: Uri,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_language_server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Tool for FakeTool {
&self,
uri: &Uri,
_range: &Range,
_only_code_action_kinds: Option<Vec<CodeActionKind>>,
_only_code_action_kinds: Option<&Vec<CodeActionKind>>,
) -> Vec<CodeActionOrCommand> {
if uri.as_str().ends_with("code_action.config") {
return vec![CodeActionOrCommand::CodeAction(CodeAction {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_language_server/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub trait Tool: Send + Sync {
&self,
_uri: &Uri,
_range: &Range,
_only_code_action_kinds: Option<Vec<CodeActionKind>>,
_only_code_action_kinds: Option<&Vec<CodeActionKind>>,
) -> Vec<CodeActionOrCommand> {
Vec::new()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_language_server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl WorkspaceWorker {
actions.extend(tool.get_code_actions_or_commands(
uri,
range,
only_code_action_kinds.clone(),
only_code_action_kinds.as_ref(),
));
}
actions
Expand Down Expand Up @@ -470,7 +470,7 @@ mod tests {

let fs = LSPFileSystem::default();
fs.set(
&Uri::from_str("file:///root/diagnostics.config").unwrap(),
Uri::from_str("file:///root/diagnostics.config").unwrap(),
"hello world".to_string(),
);

Expand Down Expand Up @@ -533,7 +533,7 @@ mod tests {

let fs = LSPFileSystem::default();
fs.set(
&Uri::from_str("file:///root/diagnostics.config").unwrap(),
Uri::from_str("file:///root/diagnostics.config").unwrap(),
"hello world".to_string(),
);

Expand Down
Loading