Skip to content

Commit 7f26e80

Browse files
committed
perf(lsp): avoid some clones, part 2
1 parent 580942b commit 7f26e80

File tree

8 files changed

+20
-21
lines changed

8 files changed

+20
-21
lines changed

crates/oxc_language_server/src/backend.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ impl LanguageServer for Backend {
8686
return Some(new_settings);
8787
}
8888

89-
let deprecated_settings = value.get("settings");
90-
9189
// the client has deprecated settings and has a deprecated root uri.
9290
// handle all things like the old way
93-
if deprecated_settings.is_some() && params.root_uri.is_some() {
91+
if let (Some(deprecated_settings), Some(root_uri)) =
92+
(value.get("settings"), params.root_uri.as_ref())
93+
{
9494
return Some(vec![WorkspaceOption {
95-
workspace_uri: params.root_uri.clone().unwrap(),
96-
options: deprecated_settings.unwrap().clone(),
95+
workspace_uri: root_uri.clone(),
96+
options: deprecated_settings.clone(),
9797
}]);
9898
}
9999

@@ -129,15 +129,14 @@ impl LanguageServer for Backend {
129129
// start the linter. We do not start the linter when the client support the request,
130130
// we will init the linter after requesting for the workspace configuration.
131131
if !capabilities.workspace_configuration || options.is_some() {
132+
let mut options = options.unwrap_or_default().into_iter();
133+
132134
for worker in &workers {
133135
let option = options
134-
.as_deref()
135-
.unwrap_or_default()
136-
.iter()
137136
.find(|workspace_option| {
138137
worker.is_responsible_for_uri(&workspace_option.workspace_uri)
139138
})
140-
.map(|workspace_options| workspace_options.options.clone())
139+
.map(|workspace_options| workspace_options.options)
141140
.unwrap_or_default();
142141

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

524523
if let Some(content) = &content {
525-
self.file_system.write().await.set(&uri, content.clone());
524+
self.file_system.write().await.set(uri.clone(), content.clone());
526525
}
527526

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

546545
let content = params.text_document.text;
547546

548-
self.file_system.write().await.set(&uri, content.clone());
547+
self.file_system.write().await.set(uri.clone(), content.clone());
549548

550549
if let Some(diagnostics) = worker.run_diagnostic(&uri, Some(&content)).await {
551550
self.client

crates/oxc_language_server/src/capabilities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tower_lsp_server::lsp_types::{
44
WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities,
55
};
66

7-
#[derive(Clone, Default)]
7+
#[derive(Default)]
88
pub struct Capabilities {
99
pub workspace_apply_edit: bool,
1010
pub workspace_configuration: bool,

crates/oxc_language_server/src/file_system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ impl LSPFileSystem {
1212
self.files.pin().clear();
1313
}
1414

15-
pub fn set(&self, uri: &Uri, content: String) {
16-
self.files.pin().insert(uri.clone(), content);
15+
pub fn set(&self, uri: Uri, content: String) {
16+
self.files.pin().insert(uri, content);
1717
}
1818

1919
pub fn get(&self, uri: &Uri) -> Option<String> {

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl Tool for ServerLinter {
458458
&self,
459459
uri: &Uri,
460460
range: &Range,
461-
only_code_action_kinds: Option<Vec<CodeActionKind>>,
461+
only_code_action_kinds: Option<&Vec<CodeActionKind>>,
462462
) -> Vec<CodeActionOrCommand> {
463463
let actions = self.get_code_actions_for_uri(uri);
464464

crates/oxc_language_server/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use tower_lsp_server::lsp_types::Uri;
33

4-
#[derive(Debug, Serialize, Deserialize, Clone)]
4+
#[derive(Debug, Serialize, Deserialize)]
55
#[serde(rename_all = "camelCase")]
66
pub struct WorkspaceOption {
77
pub workspace_uri: Uri,

crates/oxc_language_server/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Tool for FakeTool {
108108
&self,
109109
uri: &Uri,
110110
_range: &Range,
111-
_only_code_action_kinds: Option<Vec<CodeActionKind>>,
111+
_only_code_action_kinds: Option<&Vec<CodeActionKind>>,
112112
) -> Vec<CodeActionOrCommand> {
113113
if uri.as_str().ends_with("code_action.config") {
114114
return vec![CodeActionOrCommand::CodeAction(CodeAction {

crates/oxc_language_server/src/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub trait Tool: Send + Sync {
6868
&self,
6969
_uri: &Uri,
7070
_range: &Range,
71-
_only_code_action_kinds: Option<Vec<CodeActionKind>>,
71+
_only_code_action_kinds: Option<&Vec<CodeActionKind>>,
7272
) -> Vec<CodeActionOrCommand> {
7373
Vec::new()
7474
}

crates/oxc_language_server/src/worker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl WorkspaceWorker {
202202
actions.extend(tool.get_code_actions_or_commands(
203203
uri,
204204
range,
205-
only_code_action_kinds.clone(),
205+
only_code_action_kinds.as_ref(),
206206
));
207207
}
208208
actions
@@ -470,7 +470,7 @@ mod tests {
470470

471471
let fs = LSPFileSystem::default();
472472
fs.set(
473-
&Uri::from_str("file:///root/diagnostics.config").unwrap(),
473+
Uri::from_str("file:///root/diagnostics.config").unwrap(),
474474
"hello world".to_string(),
475475
);
476476

@@ -533,7 +533,7 @@ mod tests {
533533

534534
let fs = LSPFileSystem::default();
535535
fs.set(
536-
&Uri::from_str("file:///root/diagnostics.config").unwrap(),
536+
Uri::from_str("file:///root/diagnostics.config").unwrap(),
537537
"hello world".to_string(),
538538
);
539539

0 commit comments

Comments
 (0)