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

feat(rome_lsp): add link to LSP diagnostic #4099

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 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,14 @@ 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())
.and_then(|link| {
let href = Url::parse(link).ok()?;
Some(CodeDescription { href })
});

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

Expand Down Expand Up @@ -248,15 +256,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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载