Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lsp): changes for lsp_types 0.97.0 #25169

Merged
merged 11 commits into from
Aug 24, 2024
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ edition = "2021"
license = "MIT"
repository = "https://github.com/denoland/deno"

# Until https://github.com/ebkalderon/tower-lsp/pull/401 gets landed, we're
# patching it in.
[patch.crates-io]
tower-lsp = { git = "https://github.com/denoland/tower-lsp.git", rev = "910e0f8" }
nayeemrmn marked this conversation as resolved.
Show resolved Hide resolved

[workspace.dependencies]
deno_ast = { version = "=0.41.2", features = ["transpiling"] }
deno_core = { version = "0.306.0" }
Expand Down Expand Up @@ -133,7 +138,7 @@ lazy-regex = "3"
libc = "0.2.126"
libz-sys = { version = "1.1", default-features = false }
log = "0.4.20"
lsp-types = "=0.94.1" # used by tower-lsp and "proposed" feature is unstable in patch releases
lsp-types = "=0.97.0" # used by tower-lsp and "proposed" feature is unstable in patch releases
memmem = "0.1.1"
monch = "=0.5.0"
notify = "=6.1.1"
Expand Down
9 changes: 5 additions & 4 deletions cli/bench/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use deno_core::serde::Deserialize;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::url::Url;
use lsp_types::Uri;
use std::collections::HashMap;
use std::path::Path;
use std::str::FromStr;
use std::time::Duration;
use test_util::lsp::LspClientBuilder;
use test_util::PathRef;
Expand Down Expand Up @@ -91,7 +92,7 @@ fn bench_deco_apps_edits(deno_exe: &Path) -> Duration {
.build();
client.initialize(|c| {
c.set_workspace_folders(vec![lsp_types::WorkspaceFolder {
uri: Url::from_file_path(&apps).unwrap(),
uri: apps.uri_dir(),
name: "apps".to_string(),
}]);
c.set_deno_enable(true);
Expand Down Expand Up @@ -283,7 +284,7 @@ fn bench_find_replace(deno_exe: &Path) -> Duration {
"textDocument/didChange",
lsp::DidChangeTextDocumentParams {
text_document: lsp::VersionedTextDocumentIdentifier {
uri: Url::parse(&file_name).unwrap(),
uri: Uri::from_str(&file_name).unwrap(),
version: 2,
},
content_changes: vec![lsp::TextDocumentContentChangeEvent {
Expand All @@ -310,7 +311,7 @@ fn bench_find_replace(deno_exe: &Path) -> Duration {
"textDocument/formatting",
lsp::DocumentFormattingParams {
text_document: lsp::TextDocumentIdentifier {
uri: Url::parse(&file_name).unwrap(),
uri: Uri::from_str(&file_name).unwrap(),
},
options: lsp::FormattingOptions {
tab_size: 2,
Expand Down
3 changes: 3 additions & 0 deletions cli/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ disallowed-methods = [
disallowed-types = [
{ path = "reqwest::Client", reason = "use crate::http_util::HttpClient instead" },
]
ignore-interior-mutability = [
"lsp_types::Uri",
]
11 changes: 7 additions & 4 deletions cli/lsp/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::documents::Documents;
use super::language_server;
use super::resolver::LspResolver;
use super::tsc;
use super::urls::url_to_uri;

use crate::args::jsr_url;
use crate::tools::lint::CliLinter;
Expand Down Expand Up @@ -750,10 +751,11 @@ impl CodeActionCollection {
.as_ref()
.and_then(|d| serde_json::from_value::<Vec<DataQuickFix>>(d.clone()).ok())
{
let uri = url_to_uri(specifier);
for quick_fix in data_quick_fixes {
let mut changes = HashMap::new();
changes.insert(
specifier.clone(),
uri.clone(),
quick_fix
.changes
.into_iter()
Expand Down Expand Up @@ -795,6 +797,7 @@ impl CodeActionCollection {
maybe_text_info: Option<&SourceTextInfo>,
maybe_parsed_source: Option<&deno_ast::ParsedSource>,
) -> Result<(), AnyError> {
let uri = url_to_uri(specifier);
let code = diagnostic
.code
.as_ref()
Expand All @@ -811,7 +814,7 @@ impl CodeActionCollection {

let mut changes = HashMap::new();
changes.insert(
specifier.clone(),
uri.clone(),
vec![lsp::TextEdit {
new_text: prepend_whitespace(
format!("// deno-lint-ignore {code}\n"),
Expand Down Expand Up @@ -892,7 +895,7 @@ impl CodeActionCollection {
}

let mut changes = HashMap::new();
changes.insert(specifier.clone(), vec![lsp::TextEdit { new_text, range }]);
changes.insert(uri.clone(), vec![lsp::TextEdit { new_text, range }]);
let ignore_file_action = lsp::CodeAction {
title: format!("Disable {code} for the entire file"),
kind: Some(lsp::CodeActionKind::QUICKFIX),
Expand All @@ -913,7 +916,7 @@ impl CodeActionCollection {

let mut changes = HashMap::new();
changes.insert(
specifier.clone(),
uri,
vec![lsp::TextEdit {
new_text: "// deno-lint-ignore-file\n".to_string(),
range: lsp::Range {
Expand Down
3 changes: 3 additions & 0 deletions cli/lsp/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,8 @@ pub fn server_capabilities(
// TODO(nayeemrmn): Support pull-based diagnostics.
diagnostic_provider: None,
inline_value_provider: None,
inline_completion_provider: None,
// TODO(nayeemrmn); Provide!
nayeemrmn marked this conversation as resolved.
Show resolved Hide resolved
notebook_document_sync: None,
}
}
16 changes: 8 additions & 8 deletions cli/lsp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Client {
) {
self
.0
.publish_diagnostics(uri.into_url(), diags, version)
.publish_diagnostics(uri.to_uri(), diags, version)
.await;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ impl OutsideLockClient {

pub async fn workspace_configuration(
&self,
scopes: Vec<Option<lsp::Url>>,
scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, AnyError> {
self.0.workspace_configuration(scopes).await
}
Expand All @@ -159,7 +159,7 @@ impl OutsideLockClient {
trait ClientTrait: Send + Sync {
async fn publish_diagnostics(
&self,
uri: lsp::Url,
uri: lsp::Uri,
diagnostics: Vec<lsp::Diagnostic>,
version: Option<i32>,
);
Expand All @@ -182,7 +182,7 @@ trait ClientTrait: Send + Sync {
);
async fn workspace_configuration(
&self,
scopes: Vec<Option<lsp::Url>>,
scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, AnyError>;
async fn show_message(&self, message_type: lsp::MessageType, text: String);
async fn register_capability(
Expand All @@ -198,7 +198,7 @@ struct TowerClient(tower_lsp::Client);
impl ClientTrait for TowerClient {
async fn publish_diagnostics(
&self,
uri: lsp::Url,
uri: lsp::Uri,
diagnostics: Vec<lsp::Diagnostic>,
version: Option<i32>,
) {
Expand Down Expand Up @@ -276,7 +276,7 @@ impl ClientTrait for TowerClient {

async fn workspace_configuration(
&self,
scopes: Vec<Option<lsp::Url>>,
scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, AnyError> {
let config_response = self
.0
Expand Down Expand Up @@ -349,7 +349,7 @@ struct ReplClient;
impl ClientTrait for ReplClient {
async fn publish_diagnostics(
&self,
_uri: lsp::Url,
_uri: lsp::Uri,
_diagnostics: Vec<lsp::Diagnostic>,
_version: Option<i32>,
) {
Expand Down Expand Up @@ -383,7 +383,7 @@ impl ClientTrait for ReplClient {

async fn workspace_configuration(
&self,
scopes: Vec<Option<lsp::Url>>,
scopes: Vec<Option<lsp::Uri>>,
) -> Result<Vec<WorkspaceSettings>, AnyError> {
Ok(vec![get_repl_workspace_settings(); scopes.len()])
}
Expand Down
4 changes: 2 additions & 2 deletions cli/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ mod tests {
fs_sources: &[(&str, &str)],
) -> Documents {
let temp_dir = TempDir::new();
let cache = LspCache::new(Some(temp_dir.uri().join(".deno_dir").unwrap()));
let cache = LspCache::new(Some(temp_dir.url().join(".deno_dir").unwrap()));
let mut documents = Documents::default();
documents.update_config(
&Default::default(),
Expand All @@ -859,7 +859,7 @@ mod tests {
.set(&specifier, HashMap::default(), source.as_bytes())
.expect("could not cache file");
let document = documents
.get_or_load(&specifier, Some(&temp_dir.uri().join("$").unwrap()));
.get_or_load(&specifier, Some(&temp_dir.url().join("$").unwrap()));
assert!(document.is_some(), "source could not be setup");
}
documents
Expand Down
13 changes: 8 additions & 5 deletions cli/lsp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use deno_core::serde::Serialize;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
use deno_lint::linter::LintConfig as DenoLintConfig;
use deno_npm::npm_rc::ResolvedNpmRc;
Expand All @@ -38,7 +39,6 @@ use deno_runtime::deno_node::PackageJson;
use deno_runtime::deno_permissions::PermissionsContainer;
use deno_runtime::fs_util::specifier_to_file_path;
use indexmap::IndexSet;
use lsp::Url;
use lsp_types::ClientCapabilities;
use std::collections::BTreeMap;
use std::collections::HashMap;
Expand Down Expand Up @@ -844,14 +844,17 @@ pub struct Config {

impl Config {
#[cfg(test)]
pub fn new_with_roots(root_uris: impl IntoIterator<Item = Url>) -> Self {
pub fn new_with_roots(root_urls: impl IntoIterator<Item = Url>) -> Self {
use super::urls::url_to_uri;

let mut config = Self::default();
let mut folders = vec![];
for root_uri in root_uris {
let name = root_uri.path_segments().and_then(|s| s.last());
for root_url in root_urls {
let root_uri = url_to_uri(&root_url);
let name = root_url.path_segments().and_then(|s| s.last());
let name = name.unwrap_or_default().to_string();
folders.push((
root_uri.clone(),
root_url,
lsp::WorkspaceFolder {
uri: root_uri,
name,
Expand Down
Loading