Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_lsp): add link to LSP diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 23, 2022
1 parent 84812f0 commit f6982db
Show file tree
Hide file tree
Showing 110 changed files with 1,265 additions and 818 deletions.
15 changes: 12 additions & 3 deletions crates/rome_lsp/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::collections::HashMap;
use std::fmt::{Debug, Display};
use std::io;
use tower_lsp::jsonrpc::Error as LspError;
use tower_lsp::lsp_types::{self as lsp};
use tower_lsp::lsp_types::{self as lsp, CodeDescription, Url};
use tracing::error;

pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> Result<lsp::Position> {
Expand Down Expand Up @@ -217,6 +217,13 @@ pub(crate) fn diagnostic_to_lsp<D: Diagnostic>(
.category()
.map(|category| lsp::NumberOrString::String(category.name().to_string()));

let code_description = diagnostic
.category()
.and_then(|category| category.link())
.map(|link| CodeDescription {
href: Url::parse(link).unwrap(),
});

let message = PrintDescription(&diagnostic).to_string();
ensure!(!message.is_empty(), "diagnostic description is empty");

Expand Down Expand Up @@ -248,15 +255,17 @@ pub(crate) fn diagnostic_to_lsp<D: Diagnostic>(
}
};

Ok(lsp::Diagnostic::new(
let mut diagnostic = lsp::Diagnostic::new(
span,
Some(severity),
code,
Some("rome".into()),
message,
related_information,
tags,
))
);
diagnostic.code_description = code_description;
Ok(diagnostic)
}

struct RelatedInformationVisitor<'a> {
Expand Down
7 changes: 5 additions & 2 deletions crates/rome_lsp/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use tower::{Service, ServiceExt};
use tower_lsp::jsonrpc;
use tower_lsp::jsonrpc::Response;
use tower_lsp::lsp_types as lsp;
use tower_lsp::lsp_types::ClientCapabilities;
use tower_lsp::lsp_types::DidChangeTextDocumentParams;
use tower_lsp::lsp_types::DidCloseTextDocumentParams;
use tower_lsp::lsp_types::DidOpenTextDocumentParams;
Expand All @@ -45,6 +44,7 @@ use tower_lsp::lsp_types::TextDocumentItem;
use tower_lsp::lsp_types::TextEdit;
use tower_lsp::lsp_types::VersionedTextDocumentIdentifier;
use tower_lsp::lsp_types::WorkDoneProgressParams;
use tower_lsp::lsp_types::{ClientCapabilities, CodeDescription, Url};
use tower_lsp::LspService;
use tower_lsp::{jsonrpc::Request, lsp_types::InitializeParams};

Expand Down Expand Up @@ -564,7 +564,10 @@ async fn pull_diagnostics() -> Result<()> {
code: Some(lsp::NumberOrString::String(String::from(
"lint/suspicious/noDoubleEquals",
))),
code_description: None,
code_description: Some(CodeDescription {
href: Url::parse("https://docs.rome.tools/lint/rules/noDoubleEquals")
.unwrap()
}),
source: Some(String::from("rome")),
message: String::from(
"Use === instead of ==.\n== is only allowed when comparing against `null`",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build:wasm": "wasm-pack build --out-dir ../../npm/wasm-web --target web --release --scope rometools ../crates/rome_wasm",
"build:wasm-dev": "wasm-pack build --out-dir ../../npm/wasm-web --target web --dev --scope rometools ../crates/rome_wasm"
},
"dependencies": {
"devDependencies": {
"@astrojs/mdx": "^0.11.5",
"@astrojs/prism": "^1.0.2",
"@astrojs/react": "^1.2.2",
Expand Down
Loading

0 comments on commit f6982db

Please sign in to comment.