Skip to content

Commit

Permalink
Use forked version of lsp_types
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed May 9, 2019
1 parent e13a81c commit bf97ca5
Show file tree
Hide file tree
Showing 42 changed files with 218 additions and 351 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = ["./jsonrpc", "./jsonrpc_derive"]
[dependencies]
jsonrpc = { path = "jsonrpc" }
jsonrpc-derive = { path = "jsonrpc_derive" }
lsp-types = "0.56.0"
lsp-types = { git = "https://github.com/latex-lsp/lsp-types", rev = "8ce88a90c6753cf10d4b97d8cd6c9b8bb663c9d1" }
futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] }
serde = { version = "1.0.90", features = ["derive", "rc"] }
serde_json = "1.0.39"
Expand Down
36 changes: 17 additions & 19 deletions src/build/log_parser.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range};
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range, Uri};
use path_clean::PathClean;
use regex::Captures;
use regex::Match;
use regex::Regex;
use regex::{Match, Regex};
use std::borrow::Cow;
use std::cmp::Ordering;
use std::path::PathBuf;
use std::str;
use url::Url;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum BuildErrorKind {
Expand All @@ -16,14 +14,14 @@ pub enum BuildErrorKind {

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct BuildError {
pub uri: Url,
pub uri: Uri,
pub kind: BuildErrorKind,
pub message: String,
pub line: Option<u64>,
}

impl BuildError {
pub fn new(uri: Url, kind: BuildErrorKind, message: String, line: Option<u64>) -> Self {
pub fn new(uri: Uri, kind: BuildErrorKind, message: String, line: Option<u64>) -> Self {
BuildError {
uri,
kind,
Expand All @@ -45,8 +43,8 @@ impl Into<Diagnostic> for BuildError {
range,
Some(severity),
None,
Some("latex".to_owned()),
self.message,
Some(Cow::from("latex")),
Cow::from(self.message),
None,
)
}
Expand Down Expand Up @@ -85,7 +83,7 @@ impl BuildErrorParser {
}
}

pub fn parse(&self, uri: Url, log: &str) -> Vec<BuildError> {
pub fn parse(&self, uri: Uri, log: &str) -> Vec<BuildError> {
let log = self.prepare_log(log);
let mut ranges: Vec<FileRange> = self
.file_regex
Expand Down Expand Up @@ -121,7 +119,7 @@ impl BuildErrorParser {

fn extract_matches(
log: &str,
parent_uri: &Url,
parent_uri: &Uri,
ranges: &[FileRange],
regex: &Regex,
kind: BuildErrorKind,
Expand Down Expand Up @@ -182,7 +180,7 @@ impl BuildErrorParser {
new_lines.join("\n")
}

fn create_file_range(&self, parent: Url, log: &str, result: Match) -> FileRange {
fn create_file_range(&self, parent: Uri, log: &str, result: Match) -> FileRange {
let mut balance = 1;
let mut end = result.start() + 1;
let mut chars = (&log[result.start() + 1..]).chars();
Expand All @@ -204,32 +202,32 @@ impl BuildErrorParser {
base_path.pop();
let mut full_path = base_path.clone();
full_path.push(captures.name("file").unwrap().as_str());
let url = if full_path.starts_with(base_path) {
let uri = if full_path.starts_with(base_path) {
let mut full_path = PathBuf::from(full_path.to_string_lossy().replace("\\", "/"))
.clean()
.to_string_lossy()
.into_owned();
if cfg!(windows) && full_path.starts_with("/") {
full_path.remove(0);
}
Url::from_file_path(full_path).ok()
Uri::from_file_path(full_path).ok()
} else {
None
};

FileRange::new(url, result.start(), end)
FileRange::new(uri, result.start(), end)
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
struct FileRange {
pub uri: Option<Url>,
pub uri: Option<Uri>,
pub start: usize,
pub end: usize,
}

impl FileRange {
fn new(uri: Option<Url>, start: usize, end: usize) -> Self {
fn new(uri: Option<Uri>, start: usize, end: usize) -> Self {
FileRange { uri, start, end }
}

Expand Down Expand Up @@ -259,9 +257,9 @@ mod tests {
use super::*;
use std::fs;

fn create_uri(name: &str) -> Url {
fn create_uri(name: &str) -> Uri {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(name);
Url::from_file_path(path.to_str().unwrap()).unwrap()
Uri::from_file_path(path.to_str().unwrap()).unwrap()
}

fn verify(name: &str, expected: Vec<BuildError>) {
Expand Down
35 changes: 18 additions & 17 deletions src/completion/factory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use lsp_types::{CompletionItem, CompletionItemKind, InsertTextFormat};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::path::Path;

#[derive(Debug, PartialEq, Eq, Clone)]
Expand All @@ -10,11 +11,11 @@ pub enum LatexComponentId {
}

impl LatexComponentId {
fn detail(&self) -> String {
fn detail(&self) -> Cow<'static, str> {
match self {
LatexComponentId::Kernel => "built-in".to_owned(),
LatexComponentId::Unknown => "unknown".to_owned(),
LatexComponentId::User(files) => files.join(", "),
LatexComponentId::Kernel => Cow::from("built-in"),
LatexComponentId::Unknown => Cow::from("unknown"),
LatexComponentId::User(files) => Cow::from(files.join(", ")),
}
}
}
Expand Down Expand Up @@ -47,9 +48,9 @@ impl Into<serde_json::Value> for CompletionItemData {
}

pub fn create_snippet(
name: String,
name: Cow<'static, str>,
component: &LatexComponentId,
template: String,
template: Cow<'static, str>,
) -> CompletionItem {
CompletionItem {
kind: Some(CompletionItemKind::Snippet),
Expand All @@ -60,23 +61,23 @@ pub fn create_snippet(
}
}

pub fn create_command(name: String, component: &LatexComponentId) -> CompletionItem {
pub fn create_command(name: Cow<'static, str>, component: &LatexComponentId) -> CompletionItem {
CompletionItem {
kind: Some(CompletionItemKind::Function),
data: Some(CompletionItemData::Command.into()),
..CompletionItem::new_simple(name, component.detail())
}
}

pub fn create_environment(name: String, component: &LatexComponentId) -> CompletionItem {
pub fn create_environment(name: Cow<'static, str>, component: &LatexComponentId) -> CompletionItem {
CompletionItem {
kind: Some(CompletionItemKind::EnumMember),
data: Some(CompletionItemData::Environment.into()),
..CompletionItem::new_simple(name, component.detail())
}
}

pub fn create_label(name: String) -> CompletionItem {
pub fn create_label(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Field),
Expand All @@ -87,7 +88,7 @@ pub fn create_label(name: String) -> CompletionItem {

pub fn create_folder(path: &Path) -> CompletionItem {
CompletionItem {
label: path.file_name().unwrap().to_string_lossy().into_owned(),
label: Cow::from(path.file_name().unwrap().to_string_lossy().into_owned()),
kind: Some(CompletionItemKind::Folder),
data: Some(CompletionItemData::Folder.into()),
..CompletionItem::default()
Expand All @@ -96,14 +97,14 @@ pub fn create_folder(path: &Path) -> CompletionItem {

pub fn create_file(path: &Path) -> CompletionItem {
CompletionItem {
label: path.file_name().unwrap().to_string_lossy().into_owned(),
label: Cow::from(path.file_name().unwrap().to_string_lossy().into_owned()),
kind: Some(CompletionItemKind::File),
data: Some(CompletionItemData::File.into()),
..CompletionItem::default()
}
}

pub fn create_pgf_library(name: String) -> CompletionItem {
pub fn create_pgf_library(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Module),
Expand All @@ -112,7 +113,7 @@ pub fn create_pgf_library(name: String) -> CompletionItem {
}
}

pub fn create_tikz_library(name: String) -> CompletionItem {
pub fn create_tikz_library(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Color),
Expand All @@ -121,7 +122,7 @@ pub fn create_tikz_library(name: String) -> CompletionItem {
}
}

pub fn create_color(name: String) -> CompletionItem {
pub fn create_color(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Color),
Expand All @@ -130,7 +131,7 @@ pub fn create_color(name: String) -> CompletionItem {
}
}

pub fn create_color_model(name: String) -> CompletionItem {
pub fn create_color_model(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Color),
Expand All @@ -139,7 +140,7 @@ pub fn create_color_model(name: String) -> CompletionItem {
}
}

pub fn create_package(name: String) -> CompletionItem {
pub fn create_package(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Class),
Expand All @@ -148,7 +149,7 @@ pub fn create_package(name: String) -> CompletionItem {
}
}

pub fn create_class(name: String) -> CompletionItem {
pub fn create_class(name: Cow<'static, str>) -> CompletionItem {
CompletionItem {
label: name,
kind: Some(CompletionItemKind::Class),
Expand Down
5 changes: 3 additions & 2 deletions src/completion/latex/begin_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ use crate::completion::factory::LatexComponentId;
use crate::completion::latex::combinators::LatexCombinators;
use crate::feature::FeatureRequest;
use lsp_types::{CompletionItem, CompletionParams};
use std::borrow::Cow;

pub struct LatexBeginCommandCompletionProvider;

impl LatexBeginCommandCompletionProvider {
pub async fn execute(request: &FeatureRequest<CompletionParams>) -> Vec<CompletionItem> {
await!(LatexCombinators::command(request, async move |_| {
let snippet = factory::create_snippet(
"begin".to_owned(),
Cow::from("begin"),
&LatexComponentId::Kernel,
"begin{$1}\n\t$0\n\\end{$1}".to_owned(),
Cow::from("begin{$1}\n\t$0\n\\end{$1}"),
);
vec![snippet]
}))
Expand Down
3 changes: 2 additions & 1 deletion src/completion/latex/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::completion::factory;
use crate::completion::latex::combinators::LatexCombinators;
use crate::feature::FeatureRequest;
use lsp_types::{CompletionItem, CompletionParams};
use std::borrow::Cow;

pub struct LatexColorCompletionProvider;

Expand All @@ -14,7 +15,7 @@ impl LatexColorCompletionProvider {
async move |_| {
COLOR_NAMES
.iter()
.map(|name| factory::create_color((*name).to_owned()))
.map(|name| factory::create_color(Cow::from(*name)))
.collect()
}
))
Expand Down
3 changes: 2 additions & 1 deletion src/completion/latex/color_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::completion::factory;
use crate::completion::latex::combinators::LatexCombinators;
use crate::feature::FeatureRequest;
use lsp_types::{CompletionItem, CompletionParams};
use std::borrow::Cow;

pub struct LatexColorModelCompletionProvider;

Expand Down Expand Up @@ -38,7 +39,7 @@ impl LatexColorModelCompletionProvider {
fn generate_items() -> Vec<CompletionItem> {
MODEL_NAMES
.iter()
.map(|name| factory::create_color_model((*name).to_owned()))
.map(|name| factory::create_color_model(Cow::from(*name)))
.collect()
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/completion/latex/combinators.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::feature::FeatureRequest;
use crate::range;
use crate::syntax::latex::*;
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
Expand Down Expand Up @@ -76,10 +75,10 @@ impl LatexCombinators {
let command = find_non_empty_command(&nodes).or_else(|| find_empty_command(&nodes));

if let Some(command) = command {
if range::contains_exclusive(
command.args[argument_index].range(),
request.params.position,
) {
if command.args[argument_index]
.range
.contains_exclusive(request.params.position)
{
return await!(execute(command));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/completion/latex/data/actor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::completion::latex::data::types::{LatexComponent, LatexComponentDatabase};
use crate::workspace::SyntaxTree;
use futures::channel::{mpsc, oneshot};
use futures::executor::ThreadPool;
use futures::lock::Mutex;
Expand Down
3 changes: 2 additions & 1 deletion src/completion/latex/kernel_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::completion::latex::combinators::LatexCombinators;
use crate::completion::latex::kernel_primitives::KERNEL_COMMANDS;
use crate::feature::FeatureRequest;
use lsp_types::{CompletionItem, CompletionParams};
use std::borrow::Cow;

pub struct LatexKernelCommandCompletionProvider;

Expand All @@ -12,7 +13,7 @@ impl LatexKernelCommandCompletionProvider {
await!(LatexCombinators::command(&request, async move |_| {
KERNEL_COMMANDS
.iter()
.map(|name| factory::create_command((*name).to_owned(), &LatexComponentId::Kernel))
.map(|name| factory::create_command(Cow::from(*name), &LatexComponentId::Kernel))
.collect()
}))
}
Expand Down
Loading

0 comments on commit bf97ca5

Please sign in to comment.