1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

Update lspower dependency (#9179)

This commit is contained in:
hvithrafn 2021-01-29 12:34:33 -07:00 committed by GitHub
parent 11dd6f2013
commit 013b8fe606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 181 additions and 170 deletions

36
Cargo.lock generated
View file

@ -61,6 +61,12 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "ast_node" name = "ast_node"
version = "0.7.1" version = "0.7.1"
@ -1350,6 +1356,19 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" 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]] [[package]]
name = "libc" name = "libc"
version = "0.2.82" version = "0.2.82"
@ -1406,10 +1425,11 @@ dependencies = [
[[package]] [[package]]
name = "lspower" name = "lspower"
version = "0.3.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd189e0e81aa75b043a77f2861b6379042590e69c6e2c434a45ed412be8224d" checksum = "25b4cf901e2445b5f2e80bd380e0085f166692ee794953268af18f61cfad2e10"
dependencies = [ dependencies = [
"anyhow",
"async-trait", "async-trait",
"auto_impl", "auto_impl",
"bytes", "bytes",
@ -1421,6 +1441,7 @@ dependencies = [
"nom", "nom",
"serde", "serde",
"serde_json", "serde_json",
"thiserror",
"tokio", "tokio",
"tokio-util", "tokio-util",
"tower-service", "tower-service",
@ -1428,9 +1449,9 @@ dependencies = [
[[package]] [[package]]
name = "lspower-macros" name = "lspower-macros"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10b77a3b4fcd1a014a7a7a1043a5c3646068abfc75b46a9f2c4ab813d53f7c3c" checksum = "7d52f49eb53fa09a33715797d47bf4f9adbe69216ea03e1e4c3d56133b2d872c"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
@ -1589,6 +1610,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab6f70b46d6325aa300f1c7bb3d470127dfc27806d8ea6bf294ee0ce643ce2b1" checksum = "ab6f70b46d6325aa300f1c7bb3d470127dfc27806d8ea6bf294ee0ce643ce2b1"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"lexical-core",
"memchr", "memchr",
"version_check", "version_check",
] ]
@ -2458,6 +2480,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.8.1" version = "0.8.1"

View file

@ -57,7 +57,7 @@ jsonc-parser = "0.15.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
libc = "0.2.82" libc = "0.2.82"
log = { version = "0.4.13", features = ["serde"] } log = { version = "0.4.13", features = ["serde"] }
lspower = "0.3.0" lspower = "0.6.0"
notify = "5.0.0-pre.4" notify = "5.0.0-pre.4"
percent-encoding = "2.1.0" percent-encoding = "2.1.0"
pin-project = "1.0.4" pin-project = "1.0.4"

View file

@ -11,9 +11,9 @@ use crate::tools::lint::create_linter;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_lint::rules; use deno_lint::rules;
use lspower::lsp_types; use lspower::lsp;
use lspower::lsp_types::Position; use lspower::lsp::Position;
use lspower::lsp_types::Range; use lspower::lsp::Range;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
@ -77,14 +77,14 @@ pub fn get_lint_references(
pub fn references_to_diagnostics( pub fn references_to_diagnostics(
references: Vec<Reference>, references: Vec<Reference>,
) -> Vec<lsp_types::Diagnostic> { ) -> Vec<lsp::Diagnostic> {
references references
.into_iter() .into_iter()
.map(|r| match r.category { .map(|r| match r.category {
Category::Lint { message, code, .. } => lsp_types::Diagnostic { Category::Lint { message, code, .. } => lsp::Diagnostic {
range: r.range, range: r.range,
severity: Some(lsp_types::DiagnosticSeverity::Warning), severity: Some(lsp::DiagnosticSeverity::Warning),
code: Some(lsp_types::NumberOrString::String(code)), code: Some(lsp::NumberOrString::String(code)),
code_description: None, code_description: None,
source: Some("deno-lint".to_string()), source: Some("deno-lint".to_string()),
message, message,
@ -270,12 +270,12 @@ mod tests {
let actual = as_lsp_range(&fixture); let actual = as_lsp_range(&fixture);
assert_eq!( assert_eq!(
actual, actual,
lsp_types::Range { lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 0, line: 0,
character: 2, character: 2,
}, },
end: lsp_types::Position { end: lsp::Position {
line: 1, line: 1,
character: 0, character: 0,
}, },
@ -293,7 +293,7 @@ mod tests {
Router, Router,
Status, Status,
} from "https://deno.land/x/oak@v6.3.2/mod.ts"; } from "https://deno.land/x/oak@v6.3.2/mod.ts";
// @deno-types="https://deno.land/x/types/react/index.d.ts"; // @deno-types="https://deno.land/x/types/react/index.d.ts";
import * as React from "https://cdn.skypack.dev/react"; import * as React from "https://cdn.skypack.dev/react";
"#; "#;

View file

@ -5,17 +5,17 @@
///! language server, which helps determine what messages are sent from the ///! language server, which helps determine what messages are sent from the
///! client. ///! client.
///! ///!
use lspower::lsp_types::ClientCapabilities; use lspower::lsp::ClientCapabilities;
use lspower::lsp_types::CompletionOptions; use lspower::lsp::CompletionOptions;
use lspower::lsp_types::HoverProviderCapability; use lspower::lsp::HoverProviderCapability;
use lspower::lsp_types::ImplementationProviderCapability; use lspower::lsp::ImplementationProviderCapability;
use lspower::lsp_types::OneOf; use lspower::lsp::OneOf;
use lspower::lsp_types::SaveOptions; use lspower::lsp::SaveOptions;
use lspower::lsp_types::ServerCapabilities; use lspower::lsp::ServerCapabilities;
use lspower::lsp_types::TextDocumentSyncCapability; use lspower::lsp::TextDocumentSyncCapability;
use lspower::lsp_types::TextDocumentSyncKind; use lspower::lsp::TextDocumentSyncKind;
use lspower::lsp_types::TextDocumentSyncOptions; use lspower::lsp::TextDocumentSyncOptions;
use lspower::lsp_types::WorkDoneProgressOptions; use lspower::lsp::WorkDoneProgressOptions;
pub fn server_capabilities( pub fn server_capabilities(
_client_capabilities: &ClientCapabilities, _client_capabilities: &ClientCapabilities,
@ -70,7 +70,6 @@ pub fn server_capabilities(
color_provider: None, color_provider: None,
execute_command_provider: None, execute_command_provider: None,
call_hierarchy_provider: None, call_hierarchy_provider: None,
semantic_highlighting: None,
semantic_tokens_provider: None, semantic_tokens_provider: None,
workspace: None, workspace: None,
experimental: None, experimental: None,

View file

@ -6,7 +6,7 @@ use deno_core::serde_json::Value;
use deno_core::url::Url; use deno_core::url::Url;
use lspower::jsonrpc::Error as LSPError; use lspower::jsonrpc::Error as LSPError;
use lspower::jsonrpc::Result as LSPResult; use lspower::jsonrpc::Result as LSPResult;
use lspower::lsp_types; use lspower::lsp;
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct ClientCapabilities { pub struct ClientCapabilities {
@ -46,7 +46,7 @@ impl Config {
#[allow(clippy::redundant_closure_call)] #[allow(clippy::redundant_closure_call)]
pub fn update_capabilities( pub fn update_capabilities(
&mut self, &mut self,
capabilities: &lsp_types::ClientCapabilities, capabilities: &lsp::ClientCapabilities,
) { ) {
if let Some(experimental) = &capabilities.experimental { if let Some(experimental) = &capabilities.experimental {
let get_bool = let get_bool =

View file

@ -12,7 +12,7 @@ use crate::media_type::MediaType;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use lspower::lsp_types; use lspower::lsp;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::mem; use std::mem;
@ -26,7 +26,7 @@ pub enum DiagnosticSource {
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct DiagnosticCollection { pub struct DiagnosticCollection {
map: HashMap<(ModuleSpecifier, DiagnosticSource), Vec<lsp_types::Diagnostic>>, map: HashMap<(ModuleSpecifier, DiagnosticSource), Vec<lsp::Diagnostic>>,
versions: HashMap<ModuleSpecifier, i32>, versions: HashMap<ModuleSpecifier, i32>,
changes: HashSet<ModuleSpecifier>, changes: HashSet<ModuleSpecifier>,
} }
@ -37,7 +37,7 @@ impl DiagnosticCollection {
specifier: ModuleSpecifier, specifier: ModuleSpecifier,
source: DiagnosticSource, source: DiagnosticSource,
version: Option<i32>, version: Option<i32>,
diagnostics: Vec<lsp_types::Diagnostic>, diagnostics: Vec<lsp::Diagnostic>,
) { ) {
self.map.insert((specifier.clone(), source), diagnostics); self.map.insert((specifier.clone(), source), diagnostics);
if let Some(version) = version { if let Some(version) = version {
@ -50,7 +50,7 @@ impl DiagnosticCollection {
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
source: &DiagnosticSource, source: &DiagnosticSource,
) -> impl Iterator<Item = &lsp_types::Diagnostic> { ) -> impl Iterator<Item = &lsp::Diagnostic> {
self self
.map .map
.get(&(specifier.clone(), source.clone())) .get(&(specifier.clone(), source.clone()))
@ -75,7 +75,7 @@ impl DiagnosticCollection {
} }
pub type DiagnosticVec = pub type DiagnosticVec =
Vec<(ModuleSpecifier, Option<i32>, Vec<lsp_types::Diagnostic>)>; Vec<(ModuleSpecifier, Option<i32>, Vec<lsp::Diagnostic>)>;
pub async fn generate_lint_diagnostics( pub async fn generate_lint_diagnostics(
state_snapshot: StateSnapshot, state_snapshot: StateSnapshot,
@ -117,28 +117,24 @@ pub async fn generate_lint_diagnostics(
.unwrap() .unwrap()
} }
impl<'a> From<&'a diagnostics::DiagnosticCategory> impl<'a> From<&'a diagnostics::DiagnosticCategory> for lsp::DiagnosticSeverity {
for lsp_types::DiagnosticSeverity
{
fn from(category: &'a diagnostics::DiagnosticCategory) -> Self { fn from(category: &'a diagnostics::DiagnosticCategory) -> Self {
match category { match category {
diagnostics::DiagnosticCategory::Error => { diagnostics::DiagnosticCategory::Error => lsp::DiagnosticSeverity::Error,
lsp_types::DiagnosticSeverity::Error
}
diagnostics::DiagnosticCategory::Warning => { diagnostics::DiagnosticCategory::Warning => {
lsp_types::DiagnosticSeverity::Warning lsp::DiagnosticSeverity::Warning
} }
diagnostics::DiagnosticCategory::Suggestion => { diagnostics::DiagnosticCategory::Suggestion => {
lsp_types::DiagnosticSeverity::Hint lsp::DiagnosticSeverity::Hint
} }
diagnostics::DiagnosticCategory::Message => { 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 { fn from(pos: &'a diagnostics::Position) -> Self {
Self { Self {
line: pos.line as u32, line: pos.line as u32,
@ -150,8 +146,8 @@ impl<'a> From<&'a diagnostics::Position> for lsp_types::Position {
fn to_lsp_range( fn to_lsp_range(
start: &diagnostics::Position, start: &diagnostics::Position,
end: &diagnostics::Position, end: &diagnostics::Position,
) -> lsp_types::Range { ) -> lsp::Range {
lsp_types::Range { lsp::Range {
start: start.into(), start: start.into(),
end: end.into(), end: end.into(),
} }
@ -171,7 +167,7 @@ fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String {
fn to_lsp_related_information( fn to_lsp_related_information(
related_information: &Option<Vec<diagnostics::Diagnostic>>, related_information: &Option<Vec<diagnostics::Diagnostic>>,
) -> Option<Vec<lsp_types::DiagnosticRelatedInformation>> { ) -> Option<Vec<lsp::DiagnosticRelatedInformation>> {
if let Some(related) = related_information { if let Some(related) = related_information {
Some( Some(
related related
@ -180,9 +176,9 @@ fn to_lsp_related_information(
if let (Some(source), Some(start), Some(end)) = if let (Some(source), Some(start), Some(end)) =
(&ri.source, &ri.start, &ri.end) (&ri.source, &ri.start, &ri.end)
{ {
let uri = lsp_types::Url::parse(&source).unwrap(); let uri = lsp::Url::parse(&source).unwrap();
Some(lsp_types::DiagnosticRelatedInformation { Some(lsp::DiagnosticRelatedInformation {
location: lsp_types::Location { location: lsp::Location {
uri, uri,
range: to_lsp_range(start, end), range: to_lsp_range(start, end),
}, },
@ -201,15 +197,15 @@ fn to_lsp_related_information(
fn ts_json_to_diagnostics( fn ts_json_to_diagnostics(
diagnostics: &[diagnostics::Diagnostic], diagnostics: &[diagnostics::Diagnostic],
) -> Vec<lsp_types::Diagnostic> { ) -> Vec<lsp::Diagnostic> {
diagnostics diagnostics
.iter() .iter()
.filter_map(|d| { .filter_map(|d| {
if let (Some(start), Some(end)) = (&d.start, &d.end) { if let (Some(start), Some(end)) = (&d.start, &d.end) {
Some(lsp_types::Diagnostic { Some(lsp::Diagnostic {
range: to_lsp_range(start, end), range: to_lsp_range(start, end),
severity: Some((&d.category).into()), 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, code_description: None,
source: Some("deno-ts".to_string()), source: Some("deno-ts".to_string()),
message: get_diagnostic_message(d), message: get_diagnostic_message(d),
@ -219,7 +215,7 @@ fn ts_json_to_diagnostics(
tags: match d.code { tags: match d.code {
// These are codes that indicate the variable is unused. // These are codes that indicate the variable is unused.
2695 | 6133 | 6138 | 6192 | 6196 | 6198 | 6199 | 7027 | 7028 => { 2695 | 6133 | 6138 | 6192 | 6196 | 6198 | 6199 | 7027 | 7028 => {
Some(vec![lsp_types::DiagnosticTag::Unnecessary]) Some(vec![lsp::DiagnosticTag::Unnecessary])
} }
_ => None, _ => None,
}, },
@ -284,9 +280,9 @@ pub async fn generate_dependency_diagnostics(
) { ) {
match code.clone() { match code.clone() {
ResolvedDependency::Err(message) => { ResolvedDependency::Err(message) => {
diagnostic_list.push(lsp_types::Diagnostic { diagnostic_list.push(lsp::Diagnostic {
range: *range, range: *range,
severity: Some(lsp_types::DiagnosticSeverity::Error), severity: Some(lsp::DiagnosticSeverity::Error),
code: None, code: None,
code_description: None, code_description: None,
source: Some("deno".to_string()), source: Some("deno".to_string()),
@ -299,9 +295,9 @@ pub async fn generate_dependency_diagnostics(
ResolvedDependency::Resolved(specifier) => { ResolvedDependency::Resolved(specifier) => {
if !(state_snapshot.documents.contains(&specifier) || sources.contains(&specifier)) { if !(state_snapshot.documents.contains(&specifier) || sources.contains(&specifier)) {
let is_local = specifier.as_url().scheme() == "file"; let is_local = specifier.as_url().scheme() == "file";
diagnostic_list.push(lsp_types::Diagnostic { diagnostic_list.push(lsp::Diagnostic {
range: *range, range: *range,
severity: Some(lsp_types::DiagnosticSeverity::Error), severity: Some(lsp::DiagnosticSeverity::Error),
code: None, code: None,
code_description: None, code_description: None,
source: Some("deno".to_string()), source: Some("deno".to_string()),

View file

@ -10,7 +10,7 @@ use deno_core::error::custom_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::error::Context; use deno_core::error::Context;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use lspower::lsp_types::TextDocumentContentChangeEvent; use lspower::lsp::TextDocumentContentChangeEvent;
use std::collections::HashMap; use std::collections::HashMap;
use std::ops::Range; use std::ops::Range;
@ -226,7 +226,7 @@ impl DocumentCache {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use lspower::lsp_types; use lspower::lsp;
#[test] #[test]
fn test_document_cache_contains() { fn test_document_cache_contains() {
@ -256,13 +256,13 @@ mod tests {
.change( .change(
&specifier, &specifier,
2, 2,
vec![lsp_types::TextDocumentContentChangeEvent { vec![lsp::TextDocumentContentChangeEvent {
range: Some(lsp_types::Range { range: Some(lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 0, line: 0,
character: 19, character: 19,
}, },
end: lsp_types::Position { end: lsp::Position {
line: 0, line: 0,
character: 20, character: 20,
}, },
@ -291,13 +291,13 @@ mod tests {
.change( .change(
&specifier, &specifier,
2, 2,
vec![lsp_types::TextDocumentContentChangeEvent { vec![lsp::TextDocumentContentChangeEvent {
range: Some(lsp_types::Range { range: Some(lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 0, line: 0,
character: 19, character: 19,
}, },
end: lsp_types::Position { end: lsp::Position {
line: 0, line: 0,
character: 21, character: 21,
}, },

View file

@ -11,8 +11,8 @@ use deno_core::ModuleSpecifier;
use dprint_plugin_typescript as dprint; use dprint_plugin_typescript as dprint;
use lspower::jsonrpc::Error as LspError; use lspower::jsonrpc::Error as LspError;
use lspower::jsonrpc::Result as LspResult; use lspower::jsonrpc::Result as LspResult;
use lspower::lsp_types::request::*; use lspower::lsp::request::*;
use lspower::lsp_types::*; use lspower::lsp::*;
use lspower::Client; use lspower::Client;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;

View file

@ -7,8 +7,8 @@ use deno_core::serde_json::Value;
use dissimilar::diff; use dissimilar::diff;
use dissimilar::Chunk; use dissimilar::Chunk;
use lspower::jsonrpc; use lspower::jsonrpc;
use lspower::lsp_types; use lspower::lsp;
use lspower::lsp_types::TextEdit; use lspower::lsp::TextEdit;
use std::collections::HashMap; use std::collections::HashMap;
use std::ops::Bound; use std::ops::Bound;
use std::ops::RangeBounds; use std::ops::RangeBounds;
@ -123,7 +123,7 @@ impl LineIndex {
/// Convert a u16 based range to a u8 TextRange. /// Convert a u16 based range to a u8 TextRange.
pub fn get_text_range( pub fn get_text_range(
&self, &self,
range: lsp_types::Range, range: lsp::Range,
) -> Result<TextRange, AnyError> { ) -> Result<TextRange, AnyError> {
let start = self.offset(range.start)?; let start = self.offset(range.start)?;
let end = self.offset(range.end)?; let end = self.offset(range.end)?;
@ -131,10 +131,7 @@ impl LineIndex {
} }
/// Return a u8 offset based on a u16 position. /// Return a u8 offset based on a u16 position.
pub fn offset( pub fn offset(&self, position: lsp::Position) -> Result<TextSize, AnyError> {
&self,
position: lsp_types::Position,
) -> Result<TextSize, AnyError> {
let col = self.utf16_to_utf8_col(position.line, position.character); let col = self.utf16_to_utf8_col(position.line, position.character);
if let Some(line_offset) = self.utf8_offsets.get(position.line as usize) { if let Some(line_offset) = self.utf8_offsets.get(position.line as usize) {
Ok(line_offset + col) Ok(line_offset + col)
@ -145,10 +142,7 @@ impl LineIndex {
/// Convert an lsp Position into a tsc/TypeScript "position", which is really /// 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. /// an u16 byte offset from the start of the string represented as an u32.
pub fn offset_tsc( pub fn offset_tsc(&self, position: lsp::Position) -> jsonrpc::Result<u32> {
&self,
position: lsp_types::Position,
) -> jsonrpc::Result<u32> {
self self
.offset_utf16(position) .offset_utf16(position)
.map(|ts| ts.into()) .map(|ts| ts.into())
@ -157,7 +151,7 @@ impl LineIndex {
fn offset_utf16( fn offset_utf16(
&self, &self,
position: lsp_types::Position, position: lsp::Position,
) -> Result<TextSize, AnyError> { ) -> Result<TextSize, AnyError> {
if let Some(line_offset) = self.utf16_offsets.get(position.line as usize) { if let Some(line_offset) = self.utf16_offsets.get(position.line as usize) {
Ok(line_offset + TextSize::from(position.character)) 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 /// Returns a u16 position based on a u16 offset, which TypeScript offsets are
/// returned as u16. /// 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 = partition_point(&self.utf16_offsets, |&it| it <= offset) - 1;
let line_start_offset = self.utf16_offsets[line]; let line_start_offset = self.utf16_offsets[line];
let col = offset - line_start_offset; let col = offset - line_start_offset;
lsp_types::Position { lsp::Position {
line: line as u32, line: line as u32,
character: col.into(), character: col.into(),
} }
} }
/// Returns a u16 position based on a u8 offset. /// 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 = partition_point(&self.utf16_offsets, |&it| it <= offset) - 1;
let line_start_offset = self.utf16_offsets[line]; let line_start_offset = self.utf16_offsets[line];
let col = offset - line_start_offset; let col = offset - line_start_offset;
lsp_types::Position { lsp::Position {
line: line as u32, line: line as u32,
character: col.into(), character: col.into(),
} }
@ -236,7 +230,7 @@ pub fn get_edits(
let start = line_index.position_utf16(a_pos); let start = line_index.position_utf16(a_pos);
a_pos += TextSize::from(d.encode_utf16().count() as u32); a_pos += TextSize::from(d.encode_utf16().count() as u32);
let end = line_index.position_utf16(a_pos); let end = line_index.position_utf16(a_pos);
let range = lsp_types::Range { start, end }; let range = lsp::Range { start, end };
match iter.peek() { match iter.peek() {
Some(Chunk::Insert(i)) => { Some(Chunk::Insert(i)) => {
iter.next(); iter.next();
@ -253,7 +247,7 @@ pub fn get_edits(
} }
Some(Chunk::Insert(i)) => { Some(Chunk::Insert(i)) => {
let pos = line_index.position_utf16(a_pos); let pos = line_index.position_utf16(a_pos);
let range = lsp_types::Range { let range = lsp::Range {
start: pos, start: pos,
end: pos, end: pos,
}; };
@ -384,63 +378,63 @@ mod tests {
let index = LineIndex::new(text); let index = LineIndex::new(text);
assert_eq!( assert_eq!(
index.position_utf16(0.into()), index.position_utf16(0.into()),
lsp_types::Position { lsp::Position {
line: 0, line: 0,
character: 0 character: 0
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(1.into()), index.position_utf16(1.into()),
lsp_types::Position { lsp::Position {
line: 0, line: 0,
character: 1 character: 1
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(5.into()), index.position_utf16(5.into()),
lsp_types::Position { lsp::Position {
line: 0, line: 0,
character: 5 character: 5
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(6.into()), index.position_utf16(6.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 0 character: 0
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(7.into()), index.position_utf16(7.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 1 character: 1
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(8.into()), index.position_utf16(8.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 2 character: 2
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(10.into()), index.position_utf16(10.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 4 character: 4
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(11.into()), index.position_utf16(11.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 5 character: 5
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(12.into()), index.position_utf16(12.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 6 character: 6
} }
@ -450,35 +444,35 @@ mod tests {
let index = LineIndex::new(text); let index = LineIndex::new(text);
assert_eq!( assert_eq!(
index.position_utf16(0.into()), index.position_utf16(0.into()),
lsp_types::Position { lsp::Position {
line: 0, line: 0,
character: 0 character: 0
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(1.into()), index.position_utf16(1.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 0 character: 0
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(2.into()), index.position_utf16(2.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 1 character: 1
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(6.into()), index.position_utf16(6.into()),
lsp_types::Position { lsp::Position {
line: 1, line: 1,
character: 5 character: 5
} }
); );
assert_eq!( assert_eq!(
index.position_utf16(7.into()), index.position_utf16(7.into()),
lsp_types::Position { lsp::Position {
line: 2, line: 2,
character: 0 character: 0
} }
@ -578,12 +572,12 @@ const C: char = \"メ メ\";
actual, actual,
vec![ vec![
TextEdit { TextEdit {
range: lsp_types::Range { range: lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 0, line: 0,
character: 1 character: 1
}, },
end: lsp_types::Position { end: lsp::Position {
line: 0, line: 0,
character: 5 character: 5
} }
@ -591,12 +585,12 @@ const C: char = \"メ メ\";
new_text: "\nb\nchije\n".to_string() new_text: "\nb\nchije\n".to_string()
}, },
TextEdit { TextEdit {
range: lsp_types::Range { range: lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 0, line: 0,
character: 7 character: 7
}, },
end: lsp_types::Position { end: lsp::Position {
line: 0, line: 0,
character: 7 character: 7
} }
@ -616,12 +610,12 @@ const C: char = \"メ メ\";
actual, actual,
vec![ vec![
TextEdit { TextEdit {
range: lsp_types::Range { range: lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 1, line: 1,
character: 12 character: 12
}, },
end: lsp_types::Position { end: lsp::Position {
line: 1, line: 1,
character: 13 character: 13
} }
@ -629,12 +623,12 @@ const C: char = \"メ メ\";
new_text: "\"".to_string() new_text: "\"".to_string()
}, },
TextEdit { TextEdit {
range: lsp_types::Range { range: lsp::Range {
start: lsp_types::Position { start: lsp::Position {
line: 1, line: 1,
character: 23 character: 23
}, },
end: lsp_types::Position { end: lsp::Position {
line: 1, line: 1,
character: 25 character: 25
} }

View file

@ -27,7 +27,7 @@ use deno_core::JsRuntime;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_core::OpFn; use deno_core::OpFn;
use deno_core::RuntimeOptions; use deno_core::RuntimeOptions;
use lspower::lsp_types; use lspower::lsp;
use regex::Captures; use regex::Captures;
use regex::Regex; use regex::Regex;
use std::borrow::Cow; use std::borrow::Cow;
@ -313,9 +313,9 @@ pub enum ScriptElementKind {
String, String,
} }
impl From<ScriptElementKind> for lsp_types::CompletionItemKind { impl From<ScriptElementKind> for lsp::CompletionItemKind {
fn from(kind: ScriptElementKind) -> Self { fn from(kind: ScriptElementKind) -> Self {
use lspower::lsp_types::CompletionItemKind; use lspower::lsp::CompletionItemKind;
match kind { match kind {
ScriptElementKind::PrimitiveType | ScriptElementKind::Keyword => { ScriptElementKind::PrimitiveType | ScriptElementKind::Keyword => {
@ -361,8 +361,8 @@ pub struct TextSpan {
} }
impl TextSpan { impl TextSpan {
pub fn to_range(&self, line_index: &LineIndex) -> lsp_types::Range { pub fn to_range(&self, line_index: &LineIndex) -> lsp::Range {
lsp_types::Range { lsp::Range {
start: line_index.position_tsc(self.start.into()), start: line_index.position_tsc(self.start.into()),
end: line_index.position_tsc(TextSize::from(self.start + self.length)), end: line_index.position_tsc(TextSize::from(self.start + self.length)),
} }
@ -395,12 +395,12 @@ pub struct QuickInfo {
} }
impl QuickInfo { impl QuickInfo {
pub fn to_hover(&self, line_index: &LineIndex) -> lsp_types::Hover { pub fn to_hover(&self, line_index: &LineIndex) -> lsp::Hover {
let mut contents = Vec::<lsp_types::MarkedString>::new(); let mut contents = Vec::<lsp::MarkedString>::new();
if let Some(display_string) = if let Some(display_string) =
display_parts_to_string(self.display_parts.clone()) 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(), "typescript".to_string(),
display_string, display_string,
)); ));
@ -408,7 +408,7 @@ impl QuickInfo {
if let Some(documentation) = if let Some(documentation) =
display_parts_to_string(self.documentation.clone()) 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 { if let Some(tags) = &self.tags {
let tags_preview = tags let tags_preview = tags
@ -417,14 +417,14 @@ impl QuickInfo {
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(" \n\n"); .join(" \n\n");
if !tags_preview.is_empty() { if !tags_preview.is_empty() {
contents.push(lsp_types::MarkedString::from_markdown(format!( contents.push(lsp::MarkedString::from_markdown(format!(
"\n\n{}", "\n\n{}",
tags_preview tags_preview
))); )));
} }
} }
lsp_types::Hover { lsp::Hover {
contents: lsp_types::HoverContents::Array(contents), contents: lsp::HoverContents::Array(contents),
range: Some(self.text_span.to_range(line_index)), range: Some(self.text_span.to_range(line_index)),
} }
} }
@ -446,7 +446,7 @@ impl DocumentSpan {
&self, &self,
line_index: &LineIndex, line_index: &LineIndex,
index_provider: F, index_provider: F,
) -> Option<lsp_types::LocationLink> ) -> Option<lsp::LocationLink>
where where
F: Fn(ModuleSpecifier) -> Fut, F: Fn(ModuleSpecifier) -> Fut,
Fut: Future<Output = Result<LineIndex, AnyError>>, Fut: Future<Output = Result<LineIndex, AnyError>>,
@ -467,7 +467,7 @@ impl DocumentSpan {
self.text_span.to_range(&target_line_index), 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)), origin_selection_range: Some(self.text_span.to_range(line_index)),
target_uri, target_uri,
target_range, target_range,
@ -510,13 +510,13 @@ impl RenameLocations {
new_name: &str, new_name: &str,
index_provider: F, index_provider: F,
version_provider: V, version_provider: V,
) -> Result<lsp_types::WorkspaceEdit, AnyError> ) -> Result<lsp::WorkspaceEdit, AnyError>
where where
F: Fn(ModuleSpecifier) -> Fut, F: Fn(ModuleSpecifier) -> Fut,
Fut: Future<Output = Result<LineIndex, AnyError>>, Fut: Future<Output = Result<LineIndex, AnyError>>,
V: Fn(ModuleSpecifier) -> Option<i32>, V: Fn(ModuleSpecifier) -> Option<i32>,
{ {
let mut text_document_edit_map: HashMap<Url, lsp_types::TextDocumentEdit> = let mut text_document_edit_map: HashMap<Url, lsp::TextDocumentEdit> =
HashMap::new(); HashMap::new();
for location in self.locations.iter() { for location in self.locations.iter() {
let uri = utils::normalize_file_name(&location.document_span.file_name)?; 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() { if text_document_edit_map.get(&uri).is_none() {
text_document_edit_map.insert( text_document_edit_map.insert(
uri.clone(), uri.clone(),
lsp_types::TextDocumentEdit { lsp::TextDocumentEdit {
text_document: lsp_types::OptionalVersionedTextDocumentIdentifier { text_document: lsp::OptionalVersionedTextDocumentIdentifier {
uri: uri.clone(), uri: uri.clone(),
version: version_provider(specifier.clone()), version: version_provider(specifier.clone()),
}, },
edits: Vec::< edits:
lsp_types::OneOf< Vec::<lsp::OneOf<lsp::TextEdit, lsp::AnnotatedTextEdit>>::new(),
lsp_types::TextEdit,
lsp_types::AnnotatedTextEdit,
>,
>::new(),
}, },
); );
} }
// push TextEdit for ensured `TextDocumentEdit.edits`. // push TextEdit for ensured `TextDocumentEdit.edits`.
let document_edit = text_document_edit_map.get_mut(&uri).unwrap(); let document_edit = text_document_edit_map.get_mut(&uri).unwrap();
document_edit document_edit.edits.push(lsp::OneOf::Left(lsp::TextEdit {
.edits range: location
.push(lsp_types::OneOf::Left(lsp_types::TextEdit { .document_span
range: location .text_span
.document_span .to_range(&index_provider(specifier.clone()).await?),
.text_span new_text: new_name.to_string(),
.to_range(&index_provider(specifier.clone()).await?), }));
new_text: new_name.to_string(),
}));
} }
Ok(lsp_types::WorkspaceEdit { Ok(lsp::WorkspaceEdit {
change_annotations: None, change_annotations: None,
changes: None, changes: None,
document_changes: Some(lsp_types::DocumentChanges::Edits( document_changes: Some(lsp::DocumentChanges::Edits(
text_document_edit_map.values().cloned().collect(), text_document_edit_map.values().cloned().collect(),
)), )),
}) })
@ -611,13 +605,13 @@ impl DefinitionInfoAndBoundSpan {
&self, &self,
line_index: &LineIndex, line_index: &LineIndex,
index_provider: F, index_provider: F,
) -> Option<lsp_types::GotoDefinitionResponse> ) -> Option<lsp::GotoDefinitionResponse>
where where
F: Fn(ModuleSpecifier) -> Fut + Clone, F: Fn(ModuleSpecifier) -> Fut + Clone,
Fut: Future<Output = Result<LineIndex, AnyError>>, Fut: Future<Output = Result<LineIndex, AnyError>>,
{ {
if let Some(definitions) = &self.definitions { if let Some(definitions) = &self.definitions {
let mut location_links = Vec::<lsp_types::LocationLink>::new(); let mut location_links = Vec::<lsp::LocationLink>::new();
for di in definitions { for di in definitions {
if let Some(link) = di if let Some(link) = di
.document_span .document_span
@ -627,7 +621,7 @@ impl DefinitionInfoAndBoundSpan {
location_links.push(link); location_links.push(link);
} }
} }
Some(lsp_types::GotoDefinitionResponse::Link(location_links)) Some(lsp::GotoDefinitionResponse::Link(location_links))
} else { } else {
None None
} }
@ -645,17 +639,17 @@ impl DocumentHighlights {
pub fn to_highlight( pub fn to_highlight(
&self, &self,
line_index: &LineIndex, line_index: &LineIndex,
) -> Vec<lsp_types::DocumentHighlight> { ) -> Vec<lsp::DocumentHighlight> {
self self
.highlight_spans .highlight_spans
.iter() .iter()
.map(|hs| lsp_types::DocumentHighlight { .map(|hs| lsp::DocumentHighlight {
range: hs.text_span.to_range(line_index), range: hs.text_span.to_range(line_index),
kind: match hs.kind { kind: match hs.kind {
HighlightSpanKind::WrittenReference => { HighlightSpanKind::WrittenReference => {
Some(lsp_types::DocumentHighlightKind::Write) Some(lsp::DocumentHighlightKind::Write)
} }
_ => Some(lsp_types::DocumentHighlightKind::Read), _ => Some(lsp::DocumentHighlightKind::Read),
}, },
}) })
.collect() .collect()
@ -673,10 +667,10 @@ pub struct ReferenceEntry {
} }
impl 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 = let uri =
utils::normalize_file_name(&self.document_span.file_name).unwrap(); utils::normalize_file_name(&self.document_span.file_name).unwrap();
lsp_types::Location { lsp::Location {
uri, uri,
range: self.document_span.text_span.to_range(line_index), range: self.document_span.text_span.to_range(line_index),
} }
@ -694,13 +688,13 @@ impl CompletionInfo {
pub fn into_completion_response( pub fn into_completion_response(
self, self,
line_index: &LineIndex, line_index: &LineIndex,
) -> lsp_types::CompletionResponse { ) -> lsp::CompletionResponse {
let items = self let items = self
.entries .entries
.into_iter() .into_iter()
.map(|entry| entry.into_completion_item(line_index)) .map(|entry| entry.into_completion_item(line_index))
.collect(); .collect();
lsp_types::CompletionResponse::Array(items) lsp::CompletionResponse::Array(items)
} }
} }
@ -722,8 +716,8 @@ impl CompletionEntry {
pub fn into_completion_item( pub fn into_completion_item(
self, self,
line_index: &LineIndex, line_index: &LineIndex,
) -> lsp_types::CompletionItem { ) -> lsp::CompletionItem {
let mut item = lsp_types::CompletionItem { let mut item = lsp::CompletionItem {
label: self.name, label: self.name,
kind: Some(self.kind.into()), kind: Some(self.kind.into()),
sort_text: Some(self.sort_text.clone()), sort_text: Some(self.sort_text.clone()),
@ -742,15 +736,15 @@ impl CompletionEntry {
} }
match item.kind { match item.kind {
Some(lsp_types::CompletionItemKind::Function) Some(lsp::CompletionItemKind::Function)
| Some(lsp_types::CompletionItemKind::Method) => { | Some(lsp::CompletionItemKind::Method) => {
item.insert_text_format = Some(lsp_types::InsertTextFormat::Snippet); item.insert_text_format = Some(lsp::InsertTextFormat::Snippet);
} }
_ => {} _ => {}
} }
let mut insert_text = self.insert_text; let mut insert_text = self.insert_text;
let replacement_range: Option<lsp_types::Range> = let replacement_range: Option<lsp::Range> =
self.replacement_span.map(|span| span.to_range(line_index)); 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 // 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(insert_text) = insert_text {
if let Some(replacement_range) = replacement_range { if let Some(replacement_range) = replacement_range {
item.text_edit = Some(lsp_types::CompletionTextEdit::Edit( item.text_edit = Some(lsp::CompletionTextEdit::Edit(
lsp_types::TextEdit::new(replacement_range, insert_text), lsp::TextEdit::new(replacement_range, insert_text),
)); ));
} else { } else {
item.insert_text = Some(insert_text); item.insert_text = Some(insert_text);
@ -1574,7 +1568,7 @@ mod tests {
Router, Router,
Status, Status,
} from "https://deno.land/x/oak@v6.3.2/mod.ts"; } from "https://deno.land/x/oak@v6.3.2/mod.ts";
import * as test from import * as test from
"#, "#,
1, 1,