From f2d458760a22a53b7d7882eea4234f2e2a9947d7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 19:28:40 +0300 Subject: update yanked getrandom --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a6f0cc82..732932c91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -534,7 +534,7 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1350,7 +1350,7 @@ name = "rand" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1394,7 +1394,7 @@ name = "rand_core" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2073,7 +2073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -"checksum getrandom 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2512b3191f22e2763a5db387f1c9409379772e2050841722eb4a8c4f497bf096" +"checksum getrandom 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6171a6cc63fbabbe27c2b5ee268e8b7fe5dc1eb0dd2dfad537c1dfed6f69117e" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" -- cgit v1.2.3 From ccca427ce45d18d80b1876a7c5b05cf3205b86e5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 18:25:27 +0300 Subject: minor --- crates/ra_lsp_server/src/conv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index df8ea6e0d..236fdb972 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -217,7 +217,7 @@ impl ConvWith for TextEdit { } } -impl<'a> ConvWith for &'a AtomTextEdit { +impl ConvWith for &'_ AtomTextEdit { type Ctx = LineIndex; type Output = lsp_types::TextEdit; -- cgit v1.2.3 From de3f2948ea2416d65640c07d2c69df75a4273d50 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 18:26:07 +0300 Subject: add tests for crlf --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index de3bd5bc5..ec075a2fd 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -414,3 +414,49 @@ fn main() {{}} let elapsed = start.elapsed(); assert!(elapsed.as_millis() < 2000, "typing enter took {:?}", elapsed); } + +#[test] +fn preserves_dos_line_endings() { + let server = Project::with_fixture( + &r#" +//- Cargo.toml +[package] +name = "foo" +version = "0.0.0" + +//- src/main.rs +/// Some Docs\r\nfn main() {} +"#, + ) + .server(); + + server.request::( + TextDocumentPositionParams { + text_document: server.doc_id("src/main.rs"), + position: Position { line: 0, character: 8 }, + }, + json!({ + "cursorPosition": { + "position": { "line": 1, "character": 4 }, + "textDocument": { "uri": "file:///[..]src/main.rs" } + }, + "label": "on enter", + "workspaceEdit": { + "documentChanges": [ + { + "edits": [ + { + "newText": "\r\n/// ", + "range": { + "end": { "line": 0, "character": 8 }, + "start": { "line": 0, "character": 8 } + } + } + ], + "textDocument": { "uri": "file:///[..]src/main.rs", "version": null } + } + ] + } + }), + ); +} -- cgit v1.2.3 From 80a6e614465d8b16cae50f3626c15e912ad3c6f2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 18:33:23 +0300 Subject: make CTX type param instead of assoc type that way, we can implement ConvWith<&'_ CTX> for different lifetimes --- crates/ra_lsp_server/src/conv.rs | 59 +++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 236fdb972..bbe140b7a 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -19,10 +19,9 @@ pub trait Conv { fn conv(self) -> Self::Output; } -pub trait ConvWith { - type Ctx; +pub trait ConvWith { type Output; - fn conv_with(self, ctx: &Self::Ctx) -> Self::Output; + fn conv_with(self, ctx: CTX) -> Self::Output; } pub trait TryConvWith { @@ -89,8 +88,7 @@ impl Conv for Severity { } } -impl ConvWith for CompletionItem { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for CompletionItem { type Output = ::lsp_types::CompletionItem; fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { @@ -138,8 +136,7 @@ impl ConvWith for CompletionItem { } } -impl ConvWith for Position { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for Position { type Output = TextUnit; fn conv_with(self, line_index: &LineIndex) -> TextUnit { @@ -148,8 +145,7 @@ impl ConvWith for Position { } } -impl ConvWith for TextUnit { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for TextUnit { type Output = Position; fn conv_with(self, line_index: &LineIndex) -> Position { @@ -158,8 +154,7 @@ impl ConvWith for TextUnit { } } -impl ConvWith for TextRange { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for TextRange { type Output = Range; fn conv_with(self, line_index: &LineIndex) -> Range { @@ -167,8 +162,7 @@ impl ConvWith for TextRange { } } -impl ConvWith for Range { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for Range { type Output = TextRange; fn conv_with(self, line_index: &LineIndex) -> TextRange { @@ -208,8 +202,7 @@ impl Conv for ra_ide_api::FunctionSignature { } } -impl ConvWith for TextEdit { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for TextEdit { type Output = Vec; fn conv_with(self, line_index: &LineIndex) -> Vec { @@ -217,8 +210,7 @@ impl ConvWith for TextEdit { } } -impl ConvWith for &'_ AtomTextEdit { - type Ctx = LineIndex; +impl ConvWith<&'_ LineIndex> for &'_ AtomTextEdit { type Output = lsp_types::TextEdit; fn conv_with(self, line_index: &LineIndex) -> lsp_types::TextEdit { @@ -229,10 +221,10 @@ impl ConvWith for &'_ AtomTextEdit { } } -impl ConvWith for Option { - type Ctx = ::Ctx; - type Output = Option<::Output>; - fn conv_with(self, ctx: &Self::Ctx) -> Self::Output { +impl, CTX> ConvWith for Option { + type Output = Option; + + fn conv_with(self, ctx: CTX) -> Self::Output { self.map(|x| ConvWith::conv_with(x, ctx)) } } @@ -454,35 +446,34 @@ pub fn to_location( Ok(loc) } -pub trait MapConvWith<'a>: Sized + 'a { - type Ctx; +pub trait MapConvWith: Sized { type Output; - fn map_conv_with(self, ctx: &'a Self::Ctx) -> ConvWithIter<'a, Self, Self::Ctx> { + fn map_conv_with(self, ctx: CTX) -> ConvWithIter { ConvWithIter { iter: self, ctx } } } -impl<'a, I> MapConvWith<'a> for I +impl MapConvWith for I where - I: Iterator + 'a, - I::Item: ConvWith, + I: Iterator, + I::Item: ConvWith, { - type Ctx = ::Ctx; - type Output = ::Output; + type Output = >::Output; } -pub struct ConvWithIter<'a, I, Ctx: 'a> { +pub struct ConvWithIter { iter: I, - ctx: &'a Ctx, + ctx: CTX, } -impl<'a, I, Ctx> Iterator for ConvWithIter<'a, I, Ctx> +impl Iterator for ConvWithIter where I: Iterator, - I::Item: ConvWith, + I::Item: ConvWith, + CTX: Copy, { - type Item = ::Output; + type Item = >::Output; fn next(&mut self) -> Option { self.iter.next().map(|item| item.conv_with(self.ctx)) -- cgit v1.2.3 From 6ea4184fd107e5cc155b95a3cf058200c38d544d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 18:53:59 +0300 Subject: translate \n -> \r\n on the way out --- Cargo.lock | 8 +++---- Cargo.toml | 1 + crates/ra_lsp_server/src/conv.rs | 30 ++++++++++++++++---------- crates/ra_lsp_server/src/main_loop/handlers.rs | 6 ++++-- crates/ra_lsp_server/src/world.rs | 6 +++++- crates/ra_lsp_server/tests/heavy_tests/main.rs | 10 ++++----- crates/test_utils/src/lib.rs | 22 +++++++++++-------- 7 files changed, 50 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a6f0cc82..73e31f966 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,7 +1092,7 @@ dependencies = [ "ra_hir 0.1.0", "ra_ide_api 0.1.0", "ra_project_model 0.1.0", - "ra_vfs 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ra_vfs 0.2.6", "ra_vfs_glob 0.1.0", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1198,7 +1198,7 @@ dependencies = [ "ra_project_model 0.1.0", "ra_syntax 0.1.0", "ra_text_edit 0.1.0", - "ra_vfs 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ra_vfs 0.2.6", "ra_vfs_glob 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1308,7 +1308,6 @@ dependencies = [ [[package]] name = "ra_vfs" version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1324,7 +1323,7 @@ name = "ra_vfs_glob" version = "0.1.0" dependencies = [ "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ra_vfs 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ra_vfs 0.2.6", ] [[package]] @@ -2135,7 +2134,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum ra_rustc_lexer 0.1.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6baccda91574dfadd7f8a0bc8f9f110f874b6b484289b2536d3dbf4f0d5d97bb" -"checksum ra_vfs 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "865bb9e0f71916f7c7527af4843a2a67d1b0789f7c91c512a6b4ded69af98249" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" diff --git a/Cargo.toml b/Cargo.toml index e44c9570f..849a6b90c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ incremental = true debug = 1 # only line info [patch.'crates-io'] +ra_vfs = { path = "../ra_vfs" } diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index bbe140b7a..bd1ffd8f5 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -11,6 +11,7 @@ use ra_ide_api::{ }; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; +use ra_vfs::LineEndings; use crate::{req, world::WorldSnapshot, Result}; @@ -88,10 +89,10 @@ impl Conv for Severity { } } -impl ConvWith<&'_ LineIndex> for CompletionItem { +impl ConvWith<(&'_ LineIndex, LineEndings)> for CompletionItem { type Output = ::lsp_types::CompletionItem; - fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { + fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> ::lsp_types::CompletionItem { let mut additional_text_edits = Vec::new(); let mut text_edit = None; // LSP does not allow arbitrary edits in completion, so we have to do a @@ -202,22 +203,27 @@ impl Conv for ra_ide_api::FunctionSignature { } } -impl ConvWith<&'_ LineIndex> for TextEdit { +impl ConvWith<(&'_ LineIndex, LineEndings)> for TextEdit { type Output = Vec; - fn conv_with(self, line_index: &LineIndex) -> Vec { - self.as_atoms().iter().map_conv_with(line_index).collect() + fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> Vec { + self.as_atoms().iter().map_conv_with(ctx).collect() } } -impl ConvWith<&'_ LineIndex> for &'_ AtomTextEdit { +impl ConvWith<(&'_ LineIndex, LineEndings)> for &'_ AtomTextEdit { type Output = lsp_types::TextEdit; - fn conv_with(self, line_index: &LineIndex) -> lsp_types::TextEdit { - lsp_types::TextEdit { - range: self.delete.conv_with(line_index), - new_text: self.insert.clone(), + fn conv_with( + self, + (line_index, line_endings): (&LineIndex, LineEndings), + ) -> lsp_types::TextEdit { + eprintln!("line_endings = {:?}", line_endings); + let mut new_text = self.insert.clone(); + if line_endings == LineEndings::Dos { + new_text = new_text.replace('\n', "\r\n"); } + lsp_types::TextEdit { range: self.delete.conv_with(line_index), new_text } } } @@ -352,7 +358,9 @@ impl TryConvWith for SourceFileEdit { version: None, }; let line_index = world.analysis().file_line_index(self.file_id)?; - let edits = self.edit.as_atoms().iter().map_conv_with(&line_index).collect(); + let line_endings = world.file_line_endings(self.file_id); + let edits = + self.edit.as_atoms().iter().map_conv_with((&line_index, line_endings)).collect(); Ok(TextDocumentEdit { text_document, edits }) } } diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index b465707f8..3a559e845 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -138,6 +138,7 @@ pub fn handle_on_type_formatting( let _p = profile("handle_on_type_formatting"); let mut position = params.text_document_position.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(position.file_id)?; + let line_endings = world.file_line_endings(position.file_id); // in `ra_ide_api`, the `on_type` invariant is that // `text.char_at(position) == typed_char`. @@ -156,7 +157,7 @@ pub fn handle_on_type_formatting( // This should be a single-file edit let edit = edit.source_file_edits.pop().unwrap(); - let change: Vec = edit.edit.conv_with(&line_index); + let change: Vec = edit.edit.conv_with((&line_index, line_endings)); Ok(Some(change)) } @@ -370,8 +371,9 @@ pub fn handle_completion( Some(items) => items, }; let line_index = world.analysis().file_line_index(position.file_id)?; + let line_endings = world.file_line_endings(position.file_id); let items: Vec = - items.into_iter().map(|item| item.conv_with(&line_index)).collect(); + items.into_iter().map(|item| item.conv_with((&line_index, line_endings))).collect(); Ok(Some(items.into())) } diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 9990ef62e..10f96812f 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -9,7 +9,7 @@ use parking_lot::RwLock; use ra_ide_api::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, }; -use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot}; +use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot}; use ra_vfs_glob::{Glob, RustPackageFilterBuilder}; use relative_path::RelativePathBuf; @@ -210,6 +210,10 @@ impl WorldSnapshot { Ok(url) } + pub fn file_line_endings(&self, id: FileId) -> LineEndings { + self.vfs.read().file_line_endings(VfsFile(id.0)) + } + pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result { let base = self.vfs.read().root2path(VfsRoot(root.0)); let path = path.to_path(base); diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index ec075a2fd..152681062 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -208,7 +208,7 @@ pub use std::collections::HashMap; "range": { "end": { "character": 0, - "line": 6 + "line": 7 }, "start": { "character": 0, @@ -418,15 +418,15 @@ fn main() {{}} #[test] fn preserves_dos_line_endings() { let server = Project::with_fixture( - &r#" + &" //- Cargo.toml [package] -name = "foo" -version = "0.0.0" +name = \"foo\" +version = \"0.0.0\" //- src/main.rs /// Some Docs\r\nfn main() {} -"#, +", ) .server(); diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index ea99ac062..816d01f09 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -134,21 +134,25 @@ pub fn parse_fixture(fixture: &str) -> Vec { } }; }; + let margin = fixture .lines() .filter(|it| it.trim_start().starts_with("//-")) .map(|it| it.len() - it.trim_start().len()) .next() .expect("empty fixture"); - let lines = fixture.lines().filter_map(|line| { - if line.len() >= margin { - assert!(line[..margin].trim().is_empty()); - Some(&line[margin..]) - } else { - assert!(line.trim().is_empty()); - None - } - }); + + let lines = fixture + .split('\n') // don't use `.lines` to not drop `\r\n` + .filter_map(|line| { + if line.len() >= margin { + assert!(line[..margin].trim().is_empty()); + Some(&line[margin..]) + } else { + assert!(line.trim().is_empty()); + None + } + }); for line in lines { if line.starts_with("//-") { -- cgit v1.2.3 From 4753409f86bf21b8d0ba7bd83918aa951921c97c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 19:05:44 +0300 Subject: refactor TryConvWith similar to ConvWith --- crates/ra_assists/src/introduce_variable.rs | 5 +-- crates/ra_lsp_server/src/conv.rs | 68 +++++++++++------------------ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs index 5eb708310..95c18d0e3 100644 --- a/crates/ra_assists/src/introduce_variable.rs +++ b/crates/ra_assists/src/introduce_variable.rs @@ -56,10 +56,7 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx) -> Option // but we do not want to duplicate possible // extra newlines in the indent block let text = indent.text(); - if text.starts_with("\r\n") { - buf.push_str("\r\n"); - buf.push_str(text.trim_start_matches("\r\n")); - } else if text.starts_with('\n') { + if text.starts_with('\n') { buf.push_str("\n"); buf.push_str(text.trim_start_matches('\n')); } else { diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index bd1ffd8f5..1a70ec3a2 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -25,10 +25,9 @@ pub trait ConvWith { fn conv_with(self, ctx: CTX) -> Self::Output; } -pub trait TryConvWith { - type Ctx; +pub trait TryConvWith { type Output; - fn try_conv_with(self, ctx: &Self::Ctx) -> Result; + fn try_conv_with(self, ctx: CTX) -> Result; } impl Conv for SyntaxKind { @@ -235,48 +234,42 @@ impl, CTX> ConvWith for Option { } } -impl<'a> TryConvWith for &'a Url { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for &'_ Url { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { world.uri_to_file_id(self) } } -impl TryConvWith for FileId { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for FileId { type Output = Url; fn try_conv_with(self, world: &WorldSnapshot) -> Result { world.file_id_to_uri(self) } } -impl<'a> TryConvWith for &'a TextDocumentItem { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentItem { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { self.uri.try_conv_with(world) } } -impl<'a> TryConvWith for &'a VersionedTextDocumentIdentifier { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for &'_ VersionedTextDocumentIdentifier { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { self.uri.try_conv_with(world) } } -impl<'a> TryConvWith for &'a TextDocumentIdentifier { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentIdentifier { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { world.uri_to_file_id(&self.uri) } } -impl<'a> TryConvWith for &'a TextDocumentPositionParams { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentPositionParams { type Output = FilePosition; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let file_id = self.text_document.try_conv_with(world)?; @@ -286,8 +279,7 @@ impl<'a> TryConvWith for &'a TextDocumentPositionParams { } } -impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for (&'_ TextDocumentIdentifier, Range) { type Output = FileRange; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let file_id = self.0.try_conv_with(world)?; @@ -297,10 +289,9 @@ impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) { } } -impl TryConvWith for Vec { - type Ctx = ::Ctx; - type Output = Vec<::Output>; - fn try_conv_with(self, ctx: &Self::Ctx) -> Result { +impl, CTX: Copy> TryConvWith for Vec { + type Output = Vec<>::Output>; + fn try_conv_with(self, ctx: CTX) -> Result { let mut res = Vec::with_capacity(self.len()); for item in self { res.push(item.try_conv_with(ctx)?); @@ -309,8 +300,7 @@ impl TryConvWith for Vec { } } -impl TryConvWith for SourceChange { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for SourceChange { type Output = req::SourceChange; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let cursor_position = match self.cursor_position { @@ -349,8 +339,7 @@ impl TryConvWith for SourceChange { } } -impl TryConvWith for SourceFileEdit { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for SourceFileEdit { type Output = TextDocumentEdit; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let text_document = VersionedTextDocumentIdentifier { @@ -365,8 +354,7 @@ impl TryConvWith for SourceFileEdit { } } -impl TryConvWith for FileSystemEdit { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for FileSystemEdit { type Output = ResourceOp; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let res = match self { @@ -384,8 +372,7 @@ impl TryConvWith for FileSystemEdit { } } -impl TryConvWith for &NavigationTarget { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for &NavigationTarget { type Output = Location; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let line_index = world.analysis().file_line_index(self.file_id())?; @@ -394,8 +381,7 @@ impl TryConvWith for &NavigationTarget { } } -impl TryConvWith for (FileId, RangeInfo) { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for (FileId, RangeInfo) { type Output = LocationLink; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let (src_file_id, target) = self; @@ -422,8 +408,7 @@ impl TryConvWith for (FileId, RangeInfo) { } } -impl TryConvWith for (FileId, RangeInfo>) { - type Ctx = WorldSnapshot; +impl TryConvWith<&'_ WorldSnapshot> for (FileId, RangeInfo>) { type Output = req::GotoDefinitionResponse; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let (file_id, RangeInfo { range, info: navs }) = self; @@ -488,22 +473,21 @@ where } } -pub trait TryConvWithToVec<'a>: Sized + 'a { - type Ctx; +pub trait TryConvWithToVec: Sized { type Output; - fn try_conv_with_to_vec(self, ctx: &'a Self::Ctx) -> Result>; + fn try_conv_with_to_vec(self, ctx: CTX) -> Result>; } -impl<'a, I> TryConvWithToVec<'a> for I +impl TryConvWithToVec for I where - I: Iterator + 'a, - I::Item: TryConvWith, + I: Iterator, + I::Item: TryConvWith, + CTX: Copy, { - type Ctx = ::Ctx; - type Output = ::Output; + type Output = >::Output; - fn try_conv_with_to_vec(self, ctx: &'a Self::Ctx) -> Result> { + fn try_conv_with_to_vec(self, ctx: CTX) -> Result> { self.map(|it| it.try_conv_with(ctx)).collect() } } -- cgit v1.2.3 From 188c9967c0d0b6ab9acef5e879b5bbaf1a5035ed Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 19:06:22 +0300 Subject: Drop unnecessary `&'_` from impls --- crates/ra_lsp_server/src/conv.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 1a70ec3a2..818fa6d61 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -88,7 +88,7 @@ impl Conv for Severity { } } -impl ConvWith<(&'_ LineIndex, LineEndings)> for CompletionItem { +impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem { type Output = ::lsp_types::CompletionItem; fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> ::lsp_types::CompletionItem { @@ -136,7 +136,7 @@ impl ConvWith<(&'_ LineIndex, LineEndings)> for CompletionItem { } } -impl ConvWith<&'_ LineIndex> for Position { +impl ConvWith<&LineIndex> for Position { type Output = TextUnit; fn conv_with(self, line_index: &LineIndex) -> TextUnit { @@ -145,7 +145,7 @@ impl ConvWith<&'_ LineIndex> for Position { } } -impl ConvWith<&'_ LineIndex> for TextUnit { +impl ConvWith<&LineIndex> for TextUnit { type Output = Position; fn conv_with(self, line_index: &LineIndex) -> Position { @@ -154,7 +154,7 @@ impl ConvWith<&'_ LineIndex> for TextUnit { } } -impl ConvWith<&'_ LineIndex> for TextRange { +impl ConvWith<&LineIndex> for TextRange { type Output = Range; fn conv_with(self, line_index: &LineIndex) -> Range { @@ -162,7 +162,7 @@ impl ConvWith<&'_ LineIndex> for TextRange { } } -impl ConvWith<&'_ LineIndex> for Range { +impl ConvWith<&LineIndex> for Range { type Output = TextRange; fn conv_with(self, line_index: &LineIndex) -> TextRange { @@ -202,7 +202,7 @@ impl Conv for ra_ide_api::FunctionSignature { } } -impl ConvWith<(&'_ LineIndex, LineEndings)> for TextEdit { +impl ConvWith<(&LineIndex, LineEndings)> for TextEdit { type Output = Vec; fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> Vec { @@ -210,7 +210,7 @@ impl ConvWith<(&'_ LineIndex, LineEndings)> for TextEdit { } } -impl ConvWith<(&'_ LineIndex, LineEndings)> for &'_ AtomTextEdit { +impl ConvWith<(&LineIndex, LineEndings)> for &AtomTextEdit { type Output = lsp_types::TextEdit; fn conv_with( @@ -234,42 +234,42 @@ impl, CTX> ConvWith for Option { } } -impl TryConvWith<&'_ WorldSnapshot> for &'_ Url { +impl TryConvWith<&WorldSnapshot> for &Url { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { world.uri_to_file_id(self) } } -impl TryConvWith<&'_ WorldSnapshot> for FileId { +impl TryConvWith<&WorldSnapshot> for FileId { type Output = Url; fn try_conv_with(self, world: &WorldSnapshot) -> Result { world.file_id_to_uri(self) } } -impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentItem { +impl TryConvWith<&WorldSnapshot> for &TextDocumentItem { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { self.uri.try_conv_with(world) } } -impl TryConvWith<&'_ WorldSnapshot> for &'_ VersionedTextDocumentIdentifier { +impl TryConvWith<&WorldSnapshot> for &VersionedTextDocumentIdentifier { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { self.uri.try_conv_with(world) } } -impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentIdentifier { +impl TryConvWith<&WorldSnapshot> for &TextDocumentIdentifier { type Output = FileId; fn try_conv_with(self, world: &WorldSnapshot) -> Result { world.uri_to_file_id(&self.uri) } } -impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentPositionParams { +impl TryConvWith<&WorldSnapshot> for &TextDocumentPositionParams { type Output = FilePosition; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let file_id = self.text_document.try_conv_with(world)?; @@ -279,7 +279,7 @@ impl TryConvWith<&'_ WorldSnapshot> for &'_ TextDocumentPositionParams { } } -impl TryConvWith<&'_ WorldSnapshot> for (&'_ TextDocumentIdentifier, Range) { +impl TryConvWith<&WorldSnapshot> for (&TextDocumentIdentifier, Range) { type Output = FileRange; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let file_id = self.0.try_conv_with(world)?; @@ -300,7 +300,7 @@ impl, CTX: Copy> TryConvWith for Vec { } } -impl TryConvWith<&'_ WorldSnapshot> for SourceChange { +impl TryConvWith<&WorldSnapshot> for SourceChange { type Output = req::SourceChange; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let cursor_position = match self.cursor_position { @@ -339,7 +339,7 @@ impl TryConvWith<&'_ WorldSnapshot> for SourceChange { } } -impl TryConvWith<&'_ WorldSnapshot> for SourceFileEdit { +impl TryConvWith<&WorldSnapshot> for SourceFileEdit { type Output = TextDocumentEdit; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let text_document = VersionedTextDocumentIdentifier { @@ -354,7 +354,7 @@ impl TryConvWith<&'_ WorldSnapshot> for SourceFileEdit { } } -impl TryConvWith<&'_ WorldSnapshot> for FileSystemEdit { +impl TryConvWith<&WorldSnapshot> for FileSystemEdit { type Output = ResourceOp; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let res = match self { @@ -372,7 +372,7 @@ impl TryConvWith<&'_ WorldSnapshot> for FileSystemEdit { } } -impl TryConvWith<&'_ WorldSnapshot> for &NavigationTarget { +impl TryConvWith<&WorldSnapshot> for &NavigationTarget { type Output = Location; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let line_index = world.analysis().file_line_index(self.file_id())?; @@ -381,7 +381,7 @@ impl TryConvWith<&'_ WorldSnapshot> for &NavigationTarget { } } -impl TryConvWith<&'_ WorldSnapshot> for (FileId, RangeInfo) { +impl TryConvWith<&WorldSnapshot> for (FileId, RangeInfo) { type Output = LocationLink; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let (src_file_id, target) = self; @@ -408,7 +408,7 @@ impl TryConvWith<&'_ WorldSnapshot> for (FileId, RangeInfo) { } } -impl TryConvWith<&'_ WorldSnapshot> for (FileId, RangeInfo>) { +impl TryConvWith<&WorldSnapshot> for (FileId, RangeInfo>) { type Output = req::GotoDefinitionResponse; fn try_conv_with(self, world: &WorldSnapshot) -> Result { let (file_id, RangeInfo { range, info: navs }) = self; -- cgit v1.2.3 From bbeb07e5ca9f0c22e2e6f6ab33f350f24e8fff3f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 19:08:13 +0300 Subject: switch to upstream ra_vfs --- Cargo.lock | 10 ++++++---- Cargo.toml | 1 - crates/ra_lsp_server/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73e31f966..db1943477 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,7 +1092,7 @@ dependencies = [ "ra_hir 0.1.0", "ra_ide_api 0.1.0", "ra_project_model 0.1.0", - "ra_vfs 0.2.6", + "ra_vfs 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "ra_vfs_glob 0.1.0", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1198,7 +1198,7 @@ dependencies = [ "ra_project_model 0.1.0", "ra_syntax 0.1.0", "ra_text_edit 0.1.0", - "ra_vfs 0.2.6", + "ra_vfs 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "ra_vfs_glob 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1307,7 +1307,8 @@ dependencies = [ [[package]] name = "ra_vfs" -version = "0.2.6" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1323,7 +1324,7 @@ name = "ra_vfs_glob" version = "0.1.0" dependencies = [ "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ra_vfs 0.2.6", + "ra_vfs 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2134,6 +2135,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum ra_rustc_lexer 0.1.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6baccda91574dfadd7f8a0bc8f9f110f874b6b484289b2536d3dbf4f0d5d97bb" +"checksum ra_vfs 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6918c38f6ab45101f1ddd6110eda831a735b5e9ca6c96d1ceedb7d13ecaeb0f4" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" diff --git a/Cargo.toml b/Cargo.toml index 849a6b90c..e44c9570f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,3 @@ incremental = true debug = 1 # only line info [patch.'crates-io'] -ra_vfs = { path = "../ra_vfs" } diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 2c69a6993..afeac0d8a 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml @@ -16,7 +16,7 @@ lsp-types = { version = "0.60.0", features = ["proposed"] } rustc-hash = "1.0" parking_lot = "0.9.0" -ra_vfs = "0.2.0" +ra_vfs = "0.2.7" thread_worker = { path = "../thread_worker" } ra_syntax = { path = "../ra_syntax" } ra_text_edit = { path = "../ra_text_edit" } -- cgit v1.2.3 From deba1fedfaac49804896d238e16aeb32ea8a2d97 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 19:16:57 +0300 Subject: :arrow_up: rustc_lexer --- Cargo.lock | 6 +- crates/ra_syntax/Cargo.toml | 2 +- crates/ra_syntax/src/parsing/lexer.rs | 136 ++++++++++++---------------------- crates/ra_syntax/src/validation.rs | 54 +++++++------- 4 files changed, 78 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db1943477..85db6d179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1256,7 +1256,7 @@ dependencies = [ [[package]] name = "ra_rustc_lexer" -version = "0.1.0-pre.2" +version = "0.1.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1268,7 +1268,7 @@ version = "0.1.0" dependencies = [ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ra_parser 0.1.0", - "ra_rustc_lexer 0.1.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ra_rustc_lexer 0.1.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)", "ra_text_edit 0.1.0", "rowan 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2134,7 +2134,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum ra_rustc_lexer 0.1.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6baccda91574dfadd7f8a0bc8f9f110f874b6b484289b2536d3dbf4f0d5d97bb" +"checksum ra_rustc_lexer 0.1.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)" = "04371af481820ff8d35c7d12b503eb09cf9e1bd246269bf4a33e3d8c54fa3a4a" "checksum ra_vfs 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6918c38f6ab45101f1ddd6110eda831a735b5e9ca6c96d1ceedb7d13ecaeb0f4" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 5f8585878..0ead277b2 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/rust-analyzer/rust-analyzer" [dependencies] itertools = "0.8.0" rowan = "0.6.1" -ra_rustc_lexer = { version = "0.1.0-pre.2" } +ra_rustc_lexer = { version = "0.1.0-pre.3", features = ["unicode-xid"] } # ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here # to reduce number of compilations diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index 06822ea91..bdb01d40b 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -12,16 +12,16 @@ pub struct Token { pub len: TextUnit, } -fn match_literal_kind(kind: ra_rustc_lexer::LiteralKind) -> SyntaxKind { +fn match_literal_kind(kind: rustc_lexer::LiteralKind) -> SyntaxKind { match kind { - ra_rustc_lexer::LiteralKind::Int { .. } => INT_NUMBER, - ra_rustc_lexer::LiteralKind::Float { .. } => FLOAT_NUMBER, - ra_rustc_lexer::LiteralKind::Char { .. } => CHAR, - ra_rustc_lexer::LiteralKind::Byte { .. } => BYTE, - ra_rustc_lexer::LiteralKind::Str { .. } => STRING, - ra_rustc_lexer::LiteralKind::ByteStr { .. } => BYTE_STRING, - ra_rustc_lexer::LiteralKind::RawStr { .. } => RAW_STRING, - ra_rustc_lexer::LiteralKind::RawByteStr { .. } => RAW_BYTE_STRING, + rustc_lexer::LiteralKind::Int { .. } => INT_NUMBER, + rustc_lexer::LiteralKind::Float { .. } => FLOAT_NUMBER, + rustc_lexer::LiteralKind::Char { .. } => CHAR, + rustc_lexer::LiteralKind::Byte { .. } => BYTE, + rustc_lexer::LiteralKind::Str { .. } => STRING, + rustc_lexer::LiteralKind::ByteStr { .. } => BYTE_STRING, + rustc_lexer::LiteralKind::RawStr { .. } => RAW_STRING, + rustc_lexer::LiteralKind::RawByteStr { .. } => RAW_BYTE_STRING, } } @@ -32,32 +32,17 @@ pub fn tokenize(text: &str) -> Vec { } let mut text = text; let mut acc = Vec::new(); - if let Some(len) = ra_rustc_lexer::strip_shebang(text) { + if let Some(len) = rustc_lexer::strip_shebang(text) { acc.push(Token { kind: SHEBANG, len: TextUnit::from_usize(len) }); text = &text[len..]; } while !text.is_empty() { - let rustc_token = ra_rustc_lexer::first_token(text); - macro_rules! decompose { - ($t1:expr, $t2:expr) => {{ - acc.push(Token { kind: $t1, len: 1.into() }); - acc.push(Token { kind: $t2, len: 1.into() }); - text = &text[2..]; - continue; - }}; - ($t1:expr, $t2:expr, $t3:expr) => {{ - acc.push(Token { kind: $t1, len: 1.into() }); - acc.push(Token { kind: $t2, len: 1.into() }); - acc.push(Token { kind: $t3, len: 1.into() }); - text = &text[3..]; - continue; - }}; - } + let rustc_token = rustc_lexer::first_token(text); let kind = match rustc_token.kind { - ra_rustc_lexer::TokenKind::LineComment => COMMENT, - ra_rustc_lexer::TokenKind::BlockComment { .. } => COMMENT, - ra_rustc_lexer::TokenKind::Whitespace => WHITESPACE, - ra_rustc_lexer::TokenKind::Ident => { + rustc_lexer::TokenKind::LineComment => COMMENT, + rustc_lexer::TokenKind::BlockComment { .. } => COMMENT, + rustc_lexer::TokenKind::Whitespace => WHITESPACE, + rustc_lexer::TokenKind::Ident => { let token_text = &text[..rustc_token.len]; if token_text == "_" { UNDERSCORE @@ -65,62 +50,37 @@ pub fn tokenize(text: &str) -> Vec { SyntaxKind::from_keyword(&text[..rustc_token.len]).unwrap_or(IDENT) } } - ra_rustc_lexer::TokenKind::RawIdent => IDENT, - ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind), - ra_rustc_lexer::TokenKind::Lifetime { .. } => LIFETIME, - ra_rustc_lexer::TokenKind::Semi => SEMI, - ra_rustc_lexer::TokenKind::Comma => COMMA, - ra_rustc_lexer::TokenKind::DotDotDot => decompose!(DOT, DOT, DOT), - ra_rustc_lexer::TokenKind::DotDotEq => decompose!(DOT, DOT, EQ), - ra_rustc_lexer::TokenKind::DotDot => decompose!(DOT, DOT), - ra_rustc_lexer::TokenKind::Dot => DOT, - ra_rustc_lexer::TokenKind::OpenParen => L_PAREN, - ra_rustc_lexer::TokenKind::CloseParen => R_PAREN, - ra_rustc_lexer::TokenKind::OpenBrace => L_CURLY, - ra_rustc_lexer::TokenKind::CloseBrace => R_CURLY, - ra_rustc_lexer::TokenKind::OpenBracket => L_BRACK, - ra_rustc_lexer::TokenKind::CloseBracket => R_BRACK, - ra_rustc_lexer::TokenKind::At => AT, - ra_rustc_lexer::TokenKind::Pound => POUND, - ra_rustc_lexer::TokenKind::Tilde => TILDE, - ra_rustc_lexer::TokenKind::Question => QUESTION, - ra_rustc_lexer::TokenKind::ColonColon => decompose!(COLON, COLON), - ra_rustc_lexer::TokenKind::Colon => COLON, - ra_rustc_lexer::TokenKind::Dollar => DOLLAR, - ra_rustc_lexer::TokenKind::EqEq => decompose!(EQ, EQ), - ra_rustc_lexer::TokenKind::Eq => EQ, - ra_rustc_lexer::TokenKind::FatArrow => decompose!(EQ, R_ANGLE), - ra_rustc_lexer::TokenKind::Ne => decompose!(EXCL, EQ), - ra_rustc_lexer::TokenKind::Not => EXCL, - ra_rustc_lexer::TokenKind::Le => decompose!(L_ANGLE, EQ), - ra_rustc_lexer::TokenKind::LArrow => decompose!(COLON, MINUS), - ra_rustc_lexer::TokenKind::Lt => L_ANGLE, - ra_rustc_lexer::TokenKind::ShlEq => decompose!(L_ANGLE, L_ANGLE, EQ), - ra_rustc_lexer::TokenKind::Shl => decompose!(L_ANGLE, L_ANGLE), - ra_rustc_lexer::TokenKind::Ge => decompose!(R_ANGLE, EQ), - ra_rustc_lexer::TokenKind::Gt => R_ANGLE, - ra_rustc_lexer::TokenKind::ShrEq => decompose!(R_ANGLE, R_ANGLE, EQ), - ra_rustc_lexer::TokenKind::Shr => decompose!(R_ANGLE, R_ANGLE), - ra_rustc_lexer::TokenKind::RArrow => decompose!(MINUS, R_ANGLE), - ra_rustc_lexer::TokenKind::Minus => MINUS, - ra_rustc_lexer::TokenKind::MinusEq => decompose!(MINUS, EQ), - ra_rustc_lexer::TokenKind::And => AMP, - ra_rustc_lexer::TokenKind::AndAnd => decompose!(AMP, AMP), - ra_rustc_lexer::TokenKind::AndEq => decompose!(AMP, EQ), - ra_rustc_lexer::TokenKind::Or => PIPE, - ra_rustc_lexer::TokenKind::OrOr => decompose!(PIPE, PIPE), - ra_rustc_lexer::TokenKind::OrEq => decompose!(PIPE, EQ), - ra_rustc_lexer::TokenKind::PlusEq => decompose!(PLUS, EQ), - ra_rustc_lexer::TokenKind::Plus => PLUS, - ra_rustc_lexer::TokenKind::StarEq => decompose!(STAR, EQ), - ra_rustc_lexer::TokenKind::Star => STAR, - ra_rustc_lexer::TokenKind::SlashEq => decompose!(SLASH, EQ), - ra_rustc_lexer::TokenKind::Slash => SLASH, - ra_rustc_lexer::TokenKind::CaretEq => decompose!(CARET, EQ), - ra_rustc_lexer::TokenKind::Caret => CARET, - ra_rustc_lexer::TokenKind::PercentEq => decompose!(PERCENT, EQ), - ra_rustc_lexer::TokenKind::Percent => PERCENT, - ra_rustc_lexer::TokenKind::Unknown => ERROR, + rustc_lexer::TokenKind::RawIdent => IDENT, + rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind), + rustc_lexer::TokenKind::Lifetime { .. } => LIFETIME, + rustc_lexer::TokenKind::Semi => SEMI, + rustc_lexer::TokenKind::Comma => COMMA, + rustc_lexer::TokenKind::Dot => DOT, + rustc_lexer::TokenKind::OpenParen => L_PAREN, + rustc_lexer::TokenKind::CloseParen => R_PAREN, + rustc_lexer::TokenKind::OpenBrace => L_CURLY, + rustc_lexer::TokenKind::CloseBrace => R_CURLY, + rustc_lexer::TokenKind::OpenBracket => L_BRACK, + rustc_lexer::TokenKind::CloseBracket => R_BRACK, + rustc_lexer::TokenKind::At => AT, + rustc_lexer::TokenKind::Pound => POUND, + rustc_lexer::TokenKind::Tilde => TILDE, + rustc_lexer::TokenKind::Question => QUESTION, + rustc_lexer::TokenKind::Colon => COLON, + rustc_lexer::TokenKind::Dollar => DOLLAR, + rustc_lexer::TokenKind::Eq => EQ, + rustc_lexer::TokenKind::Not => EXCL, + rustc_lexer::TokenKind::Lt => L_ANGLE, + rustc_lexer::TokenKind::Gt => R_ANGLE, + rustc_lexer::TokenKind::Minus => MINUS, + rustc_lexer::TokenKind::And => AMP, + rustc_lexer::TokenKind::Or => PIPE, + rustc_lexer::TokenKind::Plus => PLUS, + rustc_lexer::TokenKind::Star => STAR, + rustc_lexer::TokenKind::Slash => SLASH, + rustc_lexer::TokenKind::Caret => CARET, + rustc_lexer::TokenKind::Percent => PERCENT, + rustc_lexer::TokenKind::Unknown => ERROR, }; let token = Token { kind, len: TextUnit::from_usize(rustc_token.len) }; acc.push(token); @@ -130,12 +90,12 @@ pub fn tokenize(text: &str) -> Vec { } pub fn classify_literal(text: &str) -> Option { - let t = ra_rustc_lexer::first_token(text); + let t = rustc_lexer::first_token(text); if t.len != text.len() { return None; } let kind = match t.kind { - ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind), + rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind), _ => return None, }; Some(Token { kind, len: TextUnit::from_usize(t.len) }) diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 2bb3c0a03..a8c789e0c 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -1,6 +1,6 @@ mod block; -use ra_rustc_lexer::unescape; +use rustc_lexer::unescape; use crate::{ algo::visit::{visitor_ctx, VisitorCtx}, @@ -32,64 +32,62 @@ pub enum EscapeError { NonAsciiCharInByte, } -impl From for EscapeError { - fn from(err: ra_rustc_lexer::unescape::EscapeError) -> Self { +impl From for EscapeError { + fn from(err: rustc_lexer::unescape::EscapeError) -> Self { match err { - ra_rustc_lexer::unescape::EscapeError::ZeroChars => EscapeError::ZeroChars, - ra_rustc_lexer::unescape::EscapeError::MoreThanOneChar => EscapeError::MoreThanOneChar, - ra_rustc_lexer::unescape::EscapeError::LoneSlash => EscapeError::LoneSlash, - ra_rustc_lexer::unescape::EscapeError::InvalidEscape => EscapeError::InvalidEscape, - ra_rustc_lexer::unescape::EscapeError::BareCarriageReturn - | ra_rustc_lexer::unescape::EscapeError::BareCarriageReturnInRawString => { + rustc_lexer::unescape::EscapeError::ZeroChars => EscapeError::ZeroChars, + rustc_lexer::unescape::EscapeError::MoreThanOneChar => EscapeError::MoreThanOneChar, + rustc_lexer::unescape::EscapeError::LoneSlash => EscapeError::LoneSlash, + rustc_lexer::unescape::EscapeError::InvalidEscape => EscapeError::InvalidEscape, + rustc_lexer::unescape::EscapeError::BareCarriageReturn + | rustc_lexer::unescape::EscapeError::BareCarriageReturnInRawString => { EscapeError::BareCarriageReturn } - ra_rustc_lexer::unescape::EscapeError::EscapeOnlyChar => EscapeError::EscapeOnlyChar, - ra_rustc_lexer::unescape::EscapeError::TooShortHexEscape => { - EscapeError::TooShortHexEscape - } - ra_rustc_lexer::unescape::EscapeError::InvalidCharInHexEscape => { + rustc_lexer::unescape::EscapeError::EscapeOnlyChar => EscapeError::EscapeOnlyChar, + rustc_lexer::unescape::EscapeError::TooShortHexEscape => EscapeError::TooShortHexEscape, + rustc_lexer::unescape::EscapeError::InvalidCharInHexEscape => { EscapeError::InvalidCharInHexEscape } - ra_rustc_lexer::unescape::EscapeError::OutOfRangeHexEscape => { + rustc_lexer::unescape::EscapeError::OutOfRangeHexEscape => { EscapeError::OutOfRangeHexEscape } - ra_rustc_lexer::unescape::EscapeError::NoBraceInUnicodeEscape => { + rustc_lexer::unescape::EscapeError::NoBraceInUnicodeEscape => { EscapeError::NoBraceInUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::InvalidCharInUnicodeEscape => { + rustc_lexer::unescape::EscapeError::InvalidCharInUnicodeEscape => { EscapeError::InvalidCharInUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::EmptyUnicodeEscape => { + rustc_lexer::unescape::EscapeError::EmptyUnicodeEscape => { EscapeError::EmptyUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::UnclosedUnicodeEscape => { + rustc_lexer::unescape::EscapeError::UnclosedUnicodeEscape => { EscapeError::UnclosedUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::LeadingUnderscoreUnicodeEscape => { + rustc_lexer::unescape::EscapeError::LeadingUnderscoreUnicodeEscape => { EscapeError::LeadingUnderscoreUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::OverlongUnicodeEscape => { + rustc_lexer::unescape::EscapeError::OverlongUnicodeEscape => { EscapeError::OverlongUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::LoneSurrogateUnicodeEscape => { + rustc_lexer::unescape::EscapeError::LoneSurrogateUnicodeEscape => { EscapeError::LoneSurrogateUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::OutOfRangeUnicodeEscape => { + rustc_lexer::unescape::EscapeError::OutOfRangeUnicodeEscape => { EscapeError::OutOfRangeUnicodeEscape } - ra_rustc_lexer::unescape::EscapeError::UnicodeEscapeInByte => { + rustc_lexer::unescape::EscapeError::UnicodeEscapeInByte => { EscapeError::UnicodeEscapeInByte } - ra_rustc_lexer::unescape::EscapeError::NonAsciiCharInByte - | ra_rustc_lexer::unescape::EscapeError::NonAsciiCharInByteString => { + rustc_lexer::unescape::EscapeError::NonAsciiCharInByte + | rustc_lexer::unescape::EscapeError::NonAsciiCharInByteString => { EscapeError::NonAsciiCharInByte } } } } -impl From for SyntaxErrorKind { - fn from(err: ra_rustc_lexer::unescape::EscapeError) -> Self { +impl From for SyntaxErrorKind { + fn from(err: rustc_lexer::unescape::EscapeError) -> Self { SyntaxErrorKind::EscapeError(err.into()) } } -- cgit v1.2.3 From 77751cfe01311d9e4fbb61c8dca352289499b3b7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Aug 2019 19:55:34 +0300 Subject: remove debug-print --- crates/ra_lsp_server/src/conv.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 818fa6d61..0ad2ea10f 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -217,7 +217,6 @@ impl ConvWith<(&LineIndex, LineEndings)> for &AtomTextEdit { self, (line_index, line_endings): (&LineIndex, LineEndings), ) -> lsp_types::TextEdit { - eprintln!("line_endings = {:?}", line_endings); let mut new_text = self.insert.clone(); if line_endings == LineEndings::Dos { new_text = new_text.replace('\n', "\r\n"); -- cgit v1.2.3