diff --git a/Cargo.lock b/Cargo.lock index 1f5183e062..f1a7311594 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,12 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "ast_node" version = "0.7.1" @@ -1350,6 +1356,19 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "lexical-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" +dependencies = [ + "arrayvec", + "bitflags", + "cfg-if 0.1.10", + "ryu", + "static_assertions", +] + [[package]] name = "libc" version = "0.2.82" @@ -1406,10 +1425,11 @@ dependencies = [ [[package]] name = "lspower" -version = "0.3.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd189e0e81aa75b043a77f2861b6379042590e69c6e2c434a45ed412be8224d" +checksum = "25b4cf901e2445b5f2e80bd380e0085f166692ee794953268af18f61cfad2e10" dependencies = [ + "anyhow", "async-trait", "auto_impl", "bytes", @@ -1421,6 +1441,7 @@ dependencies = [ "nom", "serde", "serde_json", + "thiserror", "tokio", "tokio-util", "tower-service", @@ -1428,9 +1449,9 @@ dependencies = [ [[package]] name = "lspower-macros" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10b77a3b4fcd1a014a7a7a1043a5c3646068abfc75b46a9f2c4ab813d53f7c3c" +checksum = "7d52f49eb53fa09a33715797d47bf4f9adbe69216ea03e1e4c3d56133b2d872c" dependencies = [ "heck", "proc-macro2 1.0.24", @@ -1589,6 +1610,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab6f70b46d6325aa300f1c7bb3d470127dfc27806d8ea6bf294ee0ce643ce2b1" dependencies = [ "bitvec", + "lexical-core", "memchr", "version_check", ] @@ -2458,6 +2480,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "string_cache" version = "0.8.1" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2d20e27383..4599c99dc4 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -57,7 +57,7 @@ jsonc-parser = "0.15.1" lazy_static = "1.4.0" libc = "0.2.82" log = { version = "0.4.13", features = ["serde"] } -lspower = "0.3.0" +lspower = "0.6.0" notify = "5.0.0-pre.4" percent-encoding = "2.1.0" pin-project = "1.0.4" diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 9081ce2ef3..12f7383828 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -11,9 +11,9 @@ use crate::tools::lint::create_linter; use deno_core::error::AnyError; use deno_core::ModuleSpecifier; use deno_lint::rules; -use lspower::lsp_types; -use lspower::lsp_types::Position; -use lspower::lsp_types::Range; +use lspower::lsp; +use lspower::lsp::Position; +use lspower::lsp::Range; use std::collections::HashMap; use std::rc::Rc; @@ -77,14 +77,14 @@ pub fn get_lint_references( pub fn references_to_diagnostics( references: Vec, -) -> Vec { +) -> Vec { references .into_iter() .map(|r| match r.category { - Category::Lint { message, code, .. } => lsp_types::Diagnostic { + Category::Lint { message, code, .. } => lsp::Diagnostic { range: r.range, - severity: Some(lsp_types::DiagnosticSeverity::Warning), - code: Some(lsp_types::NumberOrString::String(code)), + severity: Some(lsp::DiagnosticSeverity::Warning), + code: Some(lsp::NumberOrString::String(code)), code_description: None, source: Some("deno-lint".to_string()), message, @@ -270,12 +270,12 @@ mod tests { let actual = as_lsp_range(&fixture); assert_eq!( actual, - lsp_types::Range { - start: lsp_types::Position { + lsp::Range { + start: lsp::Position { line: 0, character: 2, }, - end: lsp_types::Position { + end: lsp::Position { line: 1, character: 0, }, @@ -293,7 +293,7 @@ mod tests { Router, Status, } from "https://deno.land/x/oak@v6.3.2/mod.ts"; - + // @deno-types="https://deno.land/x/types/react/index.d.ts"; import * as React from "https://cdn.skypack.dev/react"; "#; diff --git a/cli/lsp/capabilities.rs b/cli/lsp/capabilities.rs index 68835eba75..c83b369ce4 100644 --- a/cli/lsp/capabilities.rs +++ b/cli/lsp/capabilities.rs @@ -5,17 +5,17 @@ ///! language server, which helps determine what messages are sent from the ///! client. ///! -use lspower::lsp_types::ClientCapabilities; -use lspower::lsp_types::CompletionOptions; -use lspower::lsp_types::HoverProviderCapability; -use lspower::lsp_types::ImplementationProviderCapability; -use lspower::lsp_types::OneOf; -use lspower::lsp_types::SaveOptions; -use lspower::lsp_types::ServerCapabilities; -use lspower::lsp_types::TextDocumentSyncCapability; -use lspower::lsp_types::TextDocumentSyncKind; -use lspower::lsp_types::TextDocumentSyncOptions; -use lspower::lsp_types::WorkDoneProgressOptions; +use lspower::lsp::ClientCapabilities; +use lspower::lsp::CompletionOptions; +use lspower::lsp::HoverProviderCapability; +use lspower::lsp::ImplementationProviderCapability; +use lspower::lsp::OneOf; +use lspower::lsp::SaveOptions; +use lspower::lsp::ServerCapabilities; +use lspower::lsp::TextDocumentSyncCapability; +use lspower::lsp::TextDocumentSyncKind; +use lspower::lsp::TextDocumentSyncOptions; +use lspower::lsp::WorkDoneProgressOptions; pub fn server_capabilities( _client_capabilities: &ClientCapabilities, @@ -70,7 +70,6 @@ pub fn server_capabilities( color_provider: None, execute_command_provider: None, call_hierarchy_provider: None, - semantic_highlighting: None, semantic_tokens_provider: None, workspace: None, experimental: None, diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 7ab6d68c0d..c7cbaa992a 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -6,7 +6,7 @@ use deno_core::serde_json::Value; use deno_core::url::Url; use lspower::jsonrpc::Error as LSPError; use lspower::jsonrpc::Result as LSPResult; -use lspower::lsp_types; +use lspower::lsp; #[derive(Debug, Clone, Default)] pub struct ClientCapabilities { @@ -46,7 +46,7 @@ impl Config { #[allow(clippy::redundant_closure_call)] pub fn update_capabilities( &mut self, - capabilities: &lsp_types::ClientCapabilities, + capabilities: &lsp::ClientCapabilities, ) { if let Some(experimental) = &capabilities.experimental { let get_bool = diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index a69d0cd2df..a9e4dbefb9 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -12,7 +12,7 @@ use crate::media_type::MediaType; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::ModuleSpecifier; -use lspower::lsp_types; +use lspower::lsp; use std::collections::HashMap; use std::collections::HashSet; use std::mem; @@ -26,7 +26,7 @@ pub enum DiagnosticSource { #[derive(Debug, Default, Clone)] pub struct DiagnosticCollection { - map: HashMap<(ModuleSpecifier, DiagnosticSource), Vec>, + map: HashMap<(ModuleSpecifier, DiagnosticSource), Vec>, versions: HashMap, changes: HashSet, } @@ -37,7 +37,7 @@ impl DiagnosticCollection { specifier: ModuleSpecifier, source: DiagnosticSource, version: Option, - diagnostics: Vec, + diagnostics: Vec, ) { self.map.insert((specifier.clone(), source), diagnostics); if let Some(version) = version { @@ -50,7 +50,7 @@ impl DiagnosticCollection { &self, specifier: &ModuleSpecifier, source: &DiagnosticSource, - ) -> impl Iterator { + ) -> impl Iterator { self .map .get(&(specifier.clone(), source.clone())) @@ -75,7 +75,7 @@ impl DiagnosticCollection { } pub type DiagnosticVec = - Vec<(ModuleSpecifier, Option, Vec)>; + Vec<(ModuleSpecifier, Option, Vec)>; pub async fn generate_lint_diagnostics( state_snapshot: StateSnapshot, @@ -117,28 +117,24 @@ pub async fn generate_lint_diagnostics( .unwrap() } -impl<'a> From<&'a diagnostics::DiagnosticCategory> - for lsp_types::DiagnosticSeverity -{ +impl<'a> From<&'a diagnostics::DiagnosticCategory> for lsp::DiagnosticSeverity { fn from(category: &'a diagnostics::DiagnosticCategory) -> Self { match category { - diagnostics::DiagnosticCategory::Error => { - lsp_types::DiagnosticSeverity::Error - } + diagnostics::DiagnosticCategory::Error => lsp::DiagnosticSeverity::Error, diagnostics::DiagnosticCategory::Warning => { - lsp_types::DiagnosticSeverity::Warning + lsp::DiagnosticSeverity::Warning } diagnostics::DiagnosticCategory::Suggestion => { - lsp_types::DiagnosticSeverity::Hint + lsp::DiagnosticSeverity::Hint } diagnostics::DiagnosticCategory::Message => { - lsp_types::DiagnosticSeverity::Information + lsp::DiagnosticSeverity::Information } } } } -impl<'a> From<&'a diagnostics::Position> for lsp_types::Position { +impl<'a> From<&'a diagnostics::Position> for lsp::Position { fn from(pos: &'a diagnostics::Position) -> Self { Self { line: pos.line as u32, @@ -150,8 +146,8 @@ impl<'a> From<&'a diagnostics::Position> for lsp_types::Position { fn to_lsp_range( start: &diagnostics::Position, end: &diagnostics::Position, -) -> lsp_types::Range { - lsp_types::Range { +) -> lsp::Range { + lsp::Range { start: start.into(), end: end.into(), } @@ -171,7 +167,7 @@ fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String { fn to_lsp_related_information( related_information: &Option>, -) -> Option> { +) -> Option> { if let Some(related) = related_information { Some( related @@ -180,9 +176,9 @@ fn to_lsp_related_information( if let (Some(source), Some(start), Some(end)) = (&ri.source, &ri.start, &ri.end) { - let uri = lsp_types::Url::parse(&source).unwrap(); - Some(lsp_types::DiagnosticRelatedInformation { - location: lsp_types::Location { + let uri = lsp::Url::parse(&source).unwrap(); + Some(lsp::DiagnosticRelatedInformation { + location: lsp::Location { uri, range: to_lsp_range(start, end), }, @@ -201,15 +197,15 @@ fn to_lsp_related_information( fn ts_json_to_diagnostics( diagnostics: &[diagnostics::Diagnostic], -) -> Vec { +) -> Vec { diagnostics .iter() .filter_map(|d| { if let (Some(start), Some(end)) = (&d.start, &d.end) { - Some(lsp_types::Diagnostic { + Some(lsp::Diagnostic { range: to_lsp_range(start, end), severity: Some((&d.category).into()), - code: Some(lsp_types::NumberOrString::Number(d.code as i32)), + code: Some(lsp::NumberOrString::Number(d.code as i32)), code_description: None, source: Some("deno-ts".to_string()), message: get_diagnostic_message(d), @@ -219,7 +215,7 @@ fn ts_json_to_diagnostics( tags: match d.code { // These are codes that indicate the variable is unused. 2695 | 6133 | 6138 | 6192 | 6196 | 6198 | 6199 | 7027 | 7028 => { - Some(vec![lsp_types::DiagnosticTag::Unnecessary]) + Some(vec![lsp::DiagnosticTag::Unnecessary]) } _ => None, }, @@ -284,9 +280,9 @@ pub async fn generate_dependency_diagnostics( ) { match code.clone() { ResolvedDependency::Err(message) => { - diagnostic_list.push(lsp_types::Diagnostic { + diagnostic_list.push(lsp::Diagnostic { range: *range, - severity: Some(lsp_types::DiagnosticSeverity::Error), + severity: Some(lsp::DiagnosticSeverity::Error), code: None, code_description: None, source: Some("deno".to_string()), @@ -299,9 +295,9 @@ pub async fn generate_dependency_diagnostics( ResolvedDependency::Resolved(specifier) => { if !(state_snapshot.documents.contains(&specifier) || sources.contains(&specifier)) { let is_local = specifier.as_url().scheme() == "file"; - diagnostic_list.push(lsp_types::Diagnostic { + diagnostic_list.push(lsp::Diagnostic { range: *range, - severity: Some(lsp_types::DiagnosticSeverity::Error), + severity: Some(lsp::DiagnosticSeverity::Error), code: None, code_description: None, source: Some("deno".to_string()), diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 2f355c4d93..955ca1c782 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -10,7 +10,7 @@ use deno_core::error::custom_error; use deno_core::error::AnyError; use deno_core::error::Context; use deno_core::ModuleSpecifier; -use lspower::lsp_types::TextDocumentContentChangeEvent; +use lspower::lsp::TextDocumentContentChangeEvent; use std::collections::HashMap; use std::ops::Range; @@ -226,7 +226,7 @@ impl DocumentCache { #[cfg(test)] mod tests { use super::*; - use lspower::lsp_types; + use lspower::lsp; #[test] fn test_document_cache_contains() { @@ -256,13 +256,13 @@ mod tests { .change( &specifier, 2, - vec![lsp_types::TextDocumentContentChangeEvent { - range: Some(lsp_types::Range { - start: lsp_types::Position { + vec![lsp::TextDocumentContentChangeEvent { + range: Some(lsp::Range { + start: lsp::Position { line: 0, character: 19, }, - end: lsp_types::Position { + end: lsp::Position { line: 0, character: 20, }, @@ -291,13 +291,13 @@ mod tests { .change( &specifier, 2, - vec![lsp_types::TextDocumentContentChangeEvent { - range: Some(lsp_types::Range { - start: lsp_types::Position { + vec![lsp::TextDocumentContentChangeEvent { + range: Some(lsp::Range { + start: lsp::Position { line: 0, character: 19, }, - end: lsp_types::Position { + end: lsp::Position { line: 0, character: 21, }, diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index b892ba8d3c..087b11436a 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -11,8 +11,8 @@ use deno_core::ModuleSpecifier; use dprint_plugin_typescript as dprint; use lspower::jsonrpc::Error as LspError; use lspower::jsonrpc::Result as LspResult; -use lspower::lsp_types::request::*; -use lspower::lsp_types::*; +use lspower::lsp::request::*; +use lspower::lsp::*; use lspower::Client; use std::collections::HashMap; use std::env; diff --git a/cli/lsp/text.rs b/cli/lsp/text.rs index f444d639e6..262b27c499 100644 --- a/cli/lsp/text.rs +++ b/cli/lsp/text.rs @@ -7,8 +7,8 @@ use deno_core::serde_json::Value; use dissimilar::diff; use dissimilar::Chunk; use lspower::jsonrpc; -use lspower::lsp_types; -use lspower::lsp_types::TextEdit; +use lspower::lsp; +use lspower::lsp::TextEdit; use std::collections::HashMap; use std::ops::Bound; use std::ops::RangeBounds; @@ -123,7 +123,7 @@ impl LineIndex { /// Convert a u16 based range to a u8 TextRange. pub fn get_text_range( &self, - range: lsp_types::Range, + range: lsp::Range, ) -> Result { let start = self.offset(range.start)?; let end = self.offset(range.end)?; @@ -131,10 +131,7 @@ impl LineIndex { } /// Return a u8 offset based on a u16 position. - pub fn offset( - &self, - position: lsp_types::Position, - ) -> Result { + pub fn offset(&self, position: lsp::Position) -> Result { let col = self.utf16_to_utf8_col(position.line, position.character); if let Some(line_offset) = self.utf8_offsets.get(position.line as usize) { Ok(line_offset + col) @@ -145,10 +142,7 @@ impl LineIndex { /// Convert an lsp Position into a tsc/TypeScript "position", which is really /// an u16 byte offset from the start of the string represented as an u32. - pub fn offset_tsc( - &self, - position: lsp_types::Position, - ) -> jsonrpc::Result { + pub fn offset_tsc(&self, position: lsp::Position) -> jsonrpc::Result { self .offset_utf16(position) .map(|ts| ts.into()) @@ -157,7 +151,7 @@ impl LineIndex { fn offset_utf16( &self, - position: lsp_types::Position, + position: lsp::Position, ) -> Result { if let Some(line_offset) = self.utf16_offsets.get(position.line as usize) { Ok(line_offset + TextSize::from(position.character)) @@ -168,24 +162,24 @@ impl LineIndex { /// Returns a u16 position based on a u16 offset, which TypeScript offsets are /// returned as u16. - pub fn position_tsc(&self, offset: TextSize) -> lsp_types::Position { + pub fn position_tsc(&self, offset: TextSize) -> lsp::Position { let line = partition_point(&self.utf16_offsets, |&it| it <= offset) - 1; let line_start_offset = self.utf16_offsets[line]; let col = offset - line_start_offset; - lsp_types::Position { + lsp::Position { line: line as u32, character: col.into(), } } /// Returns a u16 position based on a u8 offset. - pub fn position_utf16(&self, offset: TextSize) -> lsp_types::Position { + pub fn position_utf16(&self, offset: TextSize) -> lsp::Position { let line = partition_point(&self.utf16_offsets, |&it| it <= offset) - 1; let line_start_offset = self.utf16_offsets[line]; let col = offset - line_start_offset; - lsp_types::Position { + lsp::Position { line: line as u32, character: col.into(), } @@ -236,7 +230,7 @@ pub fn get_edits( let start = line_index.position_utf16(a_pos); a_pos += TextSize::from(d.encode_utf16().count() as u32); let end = line_index.position_utf16(a_pos); - let range = lsp_types::Range { start, end }; + let range = lsp::Range { start, end }; match iter.peek() { Some(Chunk::Insert(i)) => { iter.next(); @@ -253,7 +247,7 @@ pub fn get_edits( } Some(Chunk::Insert(i)) => { let pos = line_index.position_utf16(a_pos); - let range = lsp_types::Range { + let range = lsp::Range { start: pos, end: pos, }; @@ -384,63 +378,63 @@ mod tests { let index = LineIndex::new(text); assert_eq!( index.position_utf16(0.into()), - lsp_types::Position { + lsp::Position { line: 0, character: 0 } ); assert_eq!( index.position_utf16(1.into()), - lsp_types::Position { + lsp::Position { line: 0, character: 1 } ); assert_eq!( index.position_utf16(5.into()), - lsp_types::Position { + lsp::Position { line: 0, character: 5 } ); assert_eq!( index.position_utf16(6.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 0 } ); assert_eq!( index.position_utf16(7.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 1 } ); assert_eq!( index.position_utf16(8.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 2 } ); assert_eq!( index.position_utf16(10.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 4 } ); assert_eq!( index.position_utf16(11.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 5 } ); assert_eq!( index.position_utf16(12.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 6 } @@ -450,35 +444,35 @@ mod tests { let index = LineIndex::new(text); assert_eq!( index.position_utf16(0.into()), - lsp_types::Position { + lsp::Position { line: 0, character: 0 } ); assert_eq!( index.position_utf16(1.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 0 } ); assert_eq!( index.position_utf16(2.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 1 } ); assert_eq!( index.position_utf16(6.into()), - lsp_types::Position { + lsp::Position { line: 1, character: 5 } ); assert_eq!( index.position_utf16(7.into()), - lsp_types::Position { + lsp::Position { line: 2, character: 0 } @@ -578,12 +572,12 @@ const C: char = \"メ メ\"; actual, vec![ TextEdit { - range: lsp_types::Range { - start: lsp_types::Position { + range: lsp::Range { + start: lsp::Position { line: 0, character: 1 }, - end: lsp_types::Position { + end: lsp::Position { line: 0, character: 5 } @@ -591,12 +585,12 @@ const C: char = \"メ メ\"; new_text: "\nb\nchije\n".to_string() }, TextEdit { - range: lsp_types::Range { - start: lsp_types::Position { + range: lsp::Range { + start: lsp::Position { line: 0, character: 7 }, - end: lsp_types::Position { + end: lsp::Position { line: 0, character: 7 } @@ -616,12 +610,12 @@ const C: char = \"メ メ\"; actual, vec![ TextEdit { - range: lsp_types::Range { - start: lsp_types::Position { + range: lsp::Range { + start: lsp::Position { line: 1, character: 12 }, - end: lsp_types::Position { + end: lsp::Position { line: 1, character: 13 } @@ -629,12 +623,12 @@ const C: char = \"メ メ\"; new_text: "\"".to_string() }, TextEdit { - range: lsp_types::Range { - start: lsp_types::Position { + range: lsp::Range { + start: lsp::Position { line: 1, character: 23 }, - end: lsp_types::Position { + end: lsp::Position { line: 1, character: 25 } diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 0ba08fdfaa..ce9f31e68c 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -27,7 +27,7 @@ use deno_core::JsRuntime; use deno_core::ModuleSpecifier; use deno_core::OpFn; use deno_core::RuntimeOptions; -use lspower::lsp_types; +use lspower::lsp; use regex::Captures; use regex::Regex; use std::borrow::Cow; @@ -313,9 +313,9 @@ pub enum ScriptElementKind { String, } -impl From for lsp_types::CompletionItemKind { +impl From for lsp::CompletionItemKind { fn from(kind: ScriptElementKind) -> Self { - use lspower::lsp_types::CompletionItemKind; + use lspower::lsp::CompletionItemKind; match kind { ScriptElementKind::PrimitiveType | ScriptElementKind::Keyword => { @@ -361,8 +361,8 @@ pub struct TextSpan { } impl TextSpan { - pub fn to_range(&self, line_index: &LineIndex) -> lsp_types::Range { - lsp_types::Range { + pub fn to_range(&self, line_index: &LineIndex) -> lsp::Range { + lsp::Range { start: line_index.position_tsc(self.start.into()), end: line_index.position_tsc(TextSize::from(self.start + self.length)), } @@ -395,12 +395,12 @@ pub struct QuickInfo { } impl QuickInfo { - pub fn to_hover(&self, line_index: &LineIndex) -> lsp_types::Hover { - let mut contents = Vec::::new(); + pub fn to_hover(&self, line_index: &LineIndex) -> lsp::Hover { + let mut contents = Vec::::new(); if let Some(display_string) = display_parts_to_string(self.display_parts.clone()) { - contents.push(lsp_types::MarkedString::from_language_code( + contents.push(lsp::MarkedString::from_language_code( "typescript".to_string(), display_string, )); @@ -408,7 +408,7 @@ impl QuickInfo { if let Some(documentation) = display_parts_to_string(self.documentation.clone()) { - contents.push(lsp_types::MarkedString::from_markdown(documentation)); + contents.push(lsp::MarkedString::from_markdown(documentation)); } if let Some(tags) = &self.tags { let tags_preview = tags @@ -417,14 +417,14 @@ impl QuickInfo { .collect::>() .join(" \n\n"); if !tags_preview.is_empty() { - contents.push(lsp_types::MarkedString::from_markdown(format!( + contents.push(lsp::MarkedString::from_markdown(format!( "\n\n{}", tags_preview ))); } } - lsp_types::Hover { - contents: lsp_types::HoverContents::Array(contents), + lsp::Hover { + contents: lsp::HoverContents::Array(contents), range: Some(self.text_span.to_range(line_index)), } } @@ -446,7 +446,7 @@ impl DocumentSpan { &self, line_index: &LineIndex, index_provider: F, - ) -> Option + ) -> Option where F: Fn(ModuleSpecifier) -> Fut, Fut: Future>, @@ -467,7 +467,7 @@ impl DocumentSpan { self.text_span.to_range(&target_line_index), ) }; - let link = lsp_types::LocationLink { + let link = lsp::LocationLink { origin_selection_range: Some(self.text_span.to_range(line_index)), target_uri, target_range, @@ -510,13 +510,13 @@ impl RenameLocations { new_name: &str, index_provider: F, version_provider: V, - ) -> Result + ) -> Result where F: Fn(ModuleSpecifier) -> Fut, Fut: Future>, V: Fn(ModuleSpecifier) -> Option, { - let mut text_document_edit_map: HashMap = + let mut text_document_edit_map: HashMap = HashMap::new(); for location in self.locations.iter() { let uri = utils::normalize_file_name(&location.document_span.file_name)?; @@ -527,38 +527,32 @@ impl RenameLocations { if text_document_edit_map.get(&uri).is_none() { text_document_edit_map.insert( uri.clone(), - lsp_types::TextDocumentEdit { - text_document: lsp_types::OptionalVersionedTextDocumentIdentifier { + lsp::TextDocumentEdit { + text_document: lsp::OptionalVersionedTextDocumentIdentifier { uri: uri.clone(), version: version_provider(specifier.clone()), }, - edits: Vec::< - lsp_types::OneOf< - lsp_types::TextEdit, - lsp_types::AnnotatedTextEdit, - >, - >::new(), + edits: + Vec::>::new(), }, ); } // push TextEdit for ensured `TextDocumentEdit.edits`. let document_edit = text_document_edit_map.get_mut(&uri).unwrap(); - document_edit - .edits - .push(lsp_types::OneOf::Left(lsp_types::TextEdit { - range: location - .document_span - .text_span - .to_range(&index_provider(specifier.clone()).await?), - new_text: new_name.to_string(), - })); + document_edit.edits.push(lsp::OneOf::Left(lsp::TextEdit { + range: location + .document_span + .text_span + .to_range(&index_provider(specifier.clone()).await?), + new_text: new_name.to_string(), + })); } - Ok(lsp_types::WorkspaceEdit { + Ok(lsp::WorkspaceEdit { change_annotations: None, changes: None, - document_changes: Some(lsp_types::DocumentChanges::Edits( + document_changes: Some(lsp::DocumentChanges::Edits( text_document_edit_map.values().cloned().collect(), )), }) @@ -611,13 +605,13 @@ impl DefinitionInfoAndBoundSpan { &self, line_index: &LineIndex, index_provider: F, - ) -> Option + ) -> Option where F: Fn(ModuleSpecifier) -> Fut + Clone, Fut: Future>, { if let Some(definitions) = &self.definitions { - let mut location_links = Vec::::new(); + let mut location_links = Vec::::new(); for di in definitions { if let Some(link) = di .document_span @@ -627,7 +621,7 @@ impl DefinitionInfoAndBoundSpan { location_links.push(link); } } - Some(lsp_types::GotoDefinitionResponse::Link(location_links)) + Some(lsp::GotoDefinitionResponse::Link(location_links)) } else { None } @@ -645,17 +639,17 @@ impl DocumentHighlights { pub fn to_highlight( &self, line_index: &LineIndex, - ) -> Vec { + ) -> Vec { self .highlight_spans .iter() - .map(|hs| lsp_types::DocumentHighlight { + .map(|hs| lsp::DocumentHighlight { range: hs.text_span.to_range(line_index), kind: match hs.kind { HighlightSpanKind::WrittenReference => { - Some(lsp_types::DocumentHighlightKind::Write) + Some(lsp::DocumentHighlightKind::Write) } - _ => Some(lsp_types::DocumentHighlightKind::Read), + _ => Some(lsp::DocumentHighlightKind::Read), }, }) .collect() @@ -673,10 +667,10 @@ pub struct ReferenceEntry { } impl ReferenceEntry { - pub fn to_location(&self, line_index: &LineIndex) -> lsp_types::Location { + pub fn to_location(&self, line_index: &LineIndex) -> lsp::Location { let uri = utils::normalize_file_name(&self.document_span.file_name).unwrap(); - lsp_types::Location { + lsp::Location { uri, range: self.document_span.text_span.to_range(line_index), } @@ -694,13 +688,13 @@ impl CompletionInfo { pub fn into_completion_response( self, line_index: &LineIndex, - ) -> lsp_types::CompletionResponse { + ) -> lsp::CompletionResponse { let items = self .entries .into_iter() .map(|entry| entry.into_completion_item(line_index)) .collect(); - lsp_types::CompletionResponse::Array(items) + lsp::CompletionResponse::Array(items) } } @@ -722,8 +716,8 @@ impl CompletionEntry { pub fn into_completion_item( self, line_index: &LineIndex, - ) -> lsp_types::CompletionItem { - let mut item = lsp_types::CompletionItem { + ) -> lsp::CompletionItem { + let mut item = lsp::CompletionItem { label: self.name, kind: Some(self.kind.into()), sort_text: Some(self.sort_text.clone()), @@ -742,15 +736,15 @@ impl CompletionEntry { } match item.kind { - Some(lsp_types::CompletionItemKind::Function) - | Some(lsp_types::CompletionItemKind::Method) => { - item.insert_text_format = Some(lsp_types::InsertTextFormat::Snippet); + Some(lsp::CompletionItemKind::Function) + | Some(lsp::CompletionItemKind::Method) => { + item.insert_text_format = Some(lsp::InsertTextFormat::Snippet); } _ => {} } let mut insert_text = self.insert_text; - let replacement_range: Option = + let replacement_range: Option = self.replacement_span.map(|span| span.to_range(line_index)); // TODO(lucacasonato): port other special cases from https://github.com/theia-ide/typescript-language-server/blob/fdf28313833cd6216d00eb4e04dc7f00f4c04f09/server/src/completion.ts#L49-L55 @@ -769,8 +763,8 @@ impl CompletionEntry { if let Some(insert_text) = insert_text { if let Some(replacement_range) = replacement_range { - item.text_edit = Some(lsp_types::CompletionTextEdit::Edit( - lsp_types::TextEdit::new(replacement_range, insert_text), + item.text_edit = Some(lsp::CompletionTextEdit::Edit( + lsp::TextEdit::new(replacement_range, insert_text), )); } else { item.insert_text = Some(insert_text); @@ -1574,7 +1568,7 @@ mod tests { Router, Status, } from "https://deno.land/x/oak@v6.3.2/mod.ts"; - + import * as test from "#, 1,