diff options
| author | hvithrafn <darinmorrison@gmail.com> | 2021-01-29 12:34:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-29 14:34:33 -0500 |
| commit | 013b8fe606ba146ad9f7d15a8a3a0e05defb0a12 (patch) | |
| tree | b889128da4f1cb43fabe204ad875ea698f520d67 | |
| parent | 11dd6f201378fe04cccadb46b7054cc2f791dda8 (diff) | |
Update lspower dependency (#9179)
| -rw-r--r-- | Cargo.lock | 36 | ||||
| -rw-r--r-- | cli/Cargo.toml | 2 | ||||
| -rw-r--r-- | cli/lsp/analysis.rs | 22 | ||||
| -rw-r--r-- | cli/lsp/capabilities.rs | 23 | ||||
| -rw-r--r-- | cli/lsp/config.rs | 4 | ||||
| -rw-r--r-- | cli/lsp/diagnostics.rs | 54 | ||||
| -rw-r--r-- | cli/lsp/documents.rs | 20 | ||||
| -rw-r--r-- | cli/lsp/language_server.rs | 4 | ||||
| -rw-r--r-- | cli/lsp/text.rs | 82 | ||||
| -rw-r--r-- | cli/lsp/tsc.rs | 104 |
10 files changed, 181 insertions, 170 deletions
diff --git a/Cargo.lock b/Cargo.lock index 1f5183e06..f1a731159 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,12 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1351,6 +1357,19 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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", ] @@ -2459,6 +2481,12 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2d20e2738..4599c99dc 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 9081ce2ef..12f738382 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<Reference>, -) -> Vec<lsp_types::Diagnostic> { +) -> Vec<lsp::Diagnostic> { 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 68835eba7..c83b369ce 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 7ab6d68c0..c7cbaa992 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 a69d0cd2d..a9e4dbefb 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<lsp_types::Diagnostic>>, + map: HashMap<(ModuleSpecifier, DiagnosticSource), Vec<lsp::Diagnostic>>, versions: HashMap<ModuleSpecifier, i32>, changes: HashSet<ModuleSpecifier>, } @@ -37,7 +37,7 @@ impl DiagnosticCollection { specifier: ModuleSpecifier, source: DiagnosticSource, version: Option<i32>, - diagnostics: Vec<lsp_types::Diagnostic>, + diagnostics: Vec<lsp::Diagnostic>, ) { 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<Item = &lsp_types::Diagnostic> { + ) -> impl Iterator<Item = &lsp::Diagnostic> { self .map .get(&(specifier.clone(), source.clone())) @@ -75,7 +75,7 @@ impl DiagnosticCollection { } pub type DiagnosticVec = - Vec<(ModuleSpecifier, Option<i32>, Vec<lsp_types::Diagnostic>)>; + Vec<(ModuleSpecifier, Option<i32>, Vec<lsp::Diagnostic>)>; 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<Vec<diagnostics::Diagnostic>>, -) -> Option<Vec<lsp_types::DiagnosticRelatedInformation>> { +) -> Option<Vec<lsp::DiagnosticRelatedInformation>> { 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<lsp_types::Diagnostic> { +) -> Vec<lsp::Diagnostic> { 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 2f355c4d9..955ca1c78 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 b892ba8d3..087b11436 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 f444d639e..262b27c49 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<TextRange, AnyError> { 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<TextSize, AnyError> { + pub fn offset(&self, position: lsp::Position) -> Result<TextSize, AnyError> { 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<u32> { + pub fn offset_tsc(&self, position: lsp::Position) -> jsonrpc::Result<u32> { 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<TextSize, AnyError> { 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