Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-lsp/src/lib.rs')
-rw-r--r--helix-lsp/src/lib.rs175
1 files changed, 3 insertions, 172 deletions
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index 259980dd..41075f2c 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -37,7 +37,7 @@ pub enum Error {
#[error("protocol error: {0}")]
Rpc(#[from] jsonrpc::Error),
#[error("failed to parse: {0}")]
- Parse(Box<dyn std::error::Error + Send + Sync>),
+ Parse(#[from] serde_json::Error),
#[error("IO Error: {0}")]
IO(#[from] std::io::Error),
#[error("request {0} timed out")]
@@ -52,19 +52,7 @@ pub enum Error {
Other(#[from] anyhow::Error),
}
-impl From<serde_json::Error> for Error {
- fn from(value: serde_json::Error) -> Self {
- Self::Parse(Box::new(value))
- }
-}
-
-impl From<sonic_rs::Error> for Error {
- fn from(value: sonic_rs::Error) -> Self {
- Self::Parse(Box::new(value))
- }
-}
-
-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum OffsetEncoding {
/// UTF-8 code units aka bytes
Utf8,
@@ -80,63 +68,7 @@ pub mod util {
use helix_core::line_ending::{line_end_byte_index, line_end_char_index};
use helix_core::snippets::{RenderedSnippet, Snippet, SnippetRenderCtx};
use helix_core::{chars, RopeSlice};
- use helix_core::{diagnostic::NumberOrString, Range, Rope, Selection, Tendril, Transaction};
-
- /// Converts a diagnostic in the document to [`lsp::Diagnostic`].
- ///
- /// Panics when [`pos_to_lsp_pos`] would for an invalid range on the diagnostic.
- pub fn diagnostic_to_lsp_diagnostic(
- doc: &Rope,
- diag: &helix_core::diagnostic::Diagnostic,
- offset_encoding: OffsetEncoding,
- ) -> lsp::Diagnostic {
- use helix_core::diagnostic::Severity::*;
-
- let range = Range::new(diag.range.start, diag.range.end);
- let severity = diag.severity.map(|s| match s {
- Hint => lsp::DiagnosticSeverity::HINT,
- Info => lsp::DiagnosticSeverity::INFORMATION,
- Warning => lsp::DiagnosticSeverity::WARNING,
- Error => lsp::DiagnosticSeverity::ERROR,
- });
-
- let code = match diag.code.clone() {
- Some(x) => match x {
- NumberOrString::Number(x) => Some(lsp::NumberOrString::Number(x)),
- NumberOrString::String(x) => Some(lsp::NumberOrString::String(x)),
- },
- None => None,
- };
-
- let new_tags: Vec<_> = diag
- .tags
- .iter()
- .map(|tag| match tag {
- helix_core::diagnostic::DiagnosticTag::Unnecessary => {
- lsp::DiagnosticTag::UNNECESSARY
- }
- helix_core::diagnostic::DiagnosticTag::Deprecated => lsp::DiagnosticTag::DEPRECATED,
- })
- .collect();
-
- let tags = if !new_tags.is_empty() {
- Some(new_tags)
- } else {
- None
- };
-
- lsp::Diagnostic {
- range: range_to_lsp_range(doc, range, offset_encoding),
- severity,
- code,
- source: diag.source.clone(),
- message: diag.message.to_owned(),
- related_information: None,
- tags,
- data: diag.data.to_owned(),
- ..Default::default()
- }
- }
+ use helix_core::{Range, Rope, Selection, Tendril, Transaction};
/// Converts [`lsp::Position`] to a position in the document.
///
@@ -475,7 +407,6 @@ pub enum MethodCall {
RegisterCapability(lsp::RegistrationParams),
UnregisterCapability(lsp::UnregistrationParams),
ShowDocument(lsp::ShowDocumentParams),
- WorkspaceDiagnosticRefresh,
}
impl MethodCall {
@@ -507,7 +438,6 @@ impl MethodCall {
let params: lsp::ShowDocumentParams = params.parse()?;
Self::ShowDocument(params)
}
- lsp::request::WorkspaceDiagnosticRefresh::METHOD => Self::WorkspaceDiagnosticRefresh,
_ => {
return Err(Error::Unhandled);
}
@@ -1082,103 +1012,4 @@ mod tests {
assert!(transaction.apply(&mut source));
assert_eq!(source, "[\n \"πŸ‡ΊπŸ‡Έ\",\n \"πŸŽ„\",\n]");
}
- #[test]
- fn rahh() {
- use helix_lsp_types::*;
- let th = [
- TextEdit {
- range: Range {
- start: Position {
- line: 1,
- character: 0,
- },
- end: Position {
- line: 1,
- character: 4,
- },
- },
- new_text: "".into(),
- },
- TextEdit {
- range: Range {
- start: Position {
- line: 2,
- character: 0,
- },
- end: Position {
- line: 3,
- character: 1,
- },
- },
- new_text: "".into(),
- },
- TextEdit {
- range: Range {
- start: Position {
- line: 3,
- character: 9,
- },
- end: Position {
- line: 3,
- character: 9,
- },
- },
- new_text: "let new =\n".into(),
- },
- TextEdit {
- range: Range {
- start: Position {
- line: 3,
- character: 20,
- },
- end: Position {
- line: 3,
- character: 29,
- },
- },
- new_text: "".into(),
- },
- TextEdit {
- range: Range {
- start: Position {
- line: 3,
- character: 56,
- },
- end: Position {
- line: 4,
- character: 24,
- },
- },
- new_text: "".into(),
- },
- TextEdit {
- range: Range {
- start: Position {
- line: 6,
- character: 1,
- },
- end: Position {
- line: 6,
- character: 1,
- },
- },
- new_text: "\n".into(),
- },
- ];
- let mut source = Rope::from_str(
- "impl Editor { // 0
- pub fn open(f: &Path) { // 1
-// 2
- let new = std::fs::read_to_string(f) // 3
- .map_err(anyhow::Error::from)?; // 4
- }
-}",
- );
- println!("{}", source);
-
- let transaction =
- generate_transaction_from_edits(&source, th.to_vec(), OffsetEncoding::Utf8);
- assert!(transaction.apply(&mut source));
- println!("{}", source);
- }
}