Allow hover suppression in multi-server setups
Rust CI vsg-bridge-ls failed CI.
MadGobblins/vsg-bridge-ls/pipeline/head There was a failure building this commit
Details
Rust CI vsg-bridge-ls failed CI.
MadGobblins/vsg-bridge-ls/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
60c30ff267
commit
8222882fb1
|
|
@ -1003,7 +1003,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|||
|
||||
[[package]]
|
||||
name = "vsg-bridge-ls"
|
||||
version = "0.3.5-rc.1"
|
||||
version = "0.3.6-rc.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "vsg-bridge-ls"
|
||||
description = "A very featureless VSG to lsp bridge"
|
||||
version = "0.3.5-rc.1"
|
||||
version = "0.3.6-rc.1"
|
||||
edition = "2021"
|
||||
rust-version = "1.85.1"
|
||||
categories =["developement-tools"]
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ The automated suite covers:
|
|||
- syntax-error location, stale-warning removal, and correction suppression;
|
||||
- default severity demotion and opt-in strict severity mapping;
|
||||
- safe project-configuration generation without overwriting existing files;
|
||||
- hover capability suppression for multi-language-server editor setups;
|
||||
- ASCII, Unicode, UTF-16 positions, CRLF, empty lines, and document boundaries;
|
||||
- missing, failing, stalled, or non-UTF-8 VSG subprocesses;
|
||||
- formatting, whole-document fixes, scoped fixes, no-op edits, and concurrent
|
||||
|
|
|
|||
36
README.md
36
README.md
|
|
@ -89,7 +89,7 @@ vsg-bridge-ls --version
|
|||
```
|
||||
|
||||
The version includes both the Cargo release and build commit, for example
|
||||
`0.3.5-rc.1+git.0123abcd`, so editor logs can identify the exact binary.
|
||||
`0.3.6-rc.1+git.0123abcd`, so editor logs can identify the exact binary.
|
||||
|
||||
### Generate a project configuration
|
||||
|
||||
|
|
@ -115,6 +115,8 @@ the useful bridge settings:
|
|||
fix.
|
||||
- `allow_browser_action`: allow documentation actions to open HTTPS links.
|
||||
- `debug_mode`: expose a troubleshooting snapshot through hover and actions.
|
||||
- `disable_hover`: suppress VSG hover text when another language server should
|
||||
own hover presentation.
|
||||
|
||||
Edit the generated TOML as needed and restart the editor language server.
|
||||
Explicit command-line options still take priority over configuration files.
|
||||
|
|
@ -136,6 +138,8 @@ args = [
|
|||
# "--experimental-multi-rule-line-fix",
|
||||
# Uncomment the next line to expose debug information in hover and an action.
|
||||
# "--debug-mode",
|
||||
# Uncomment to leave hover entirely to another VHDL language server.
|
||||
# "--disable-hover",
|
||||
# Uncomment to preserve VSG's strict Error/Warning diagnostic levels.
|
||||
# "--strict-diagnostic-severity",
|
||||
]
|
||||
|
|
@ -172,6 +176,36 @@ phase, fixability, relevant configuration, and available documentation links.
|
|||
With `--allow-browser-action`, clients supporting LSP `window/showDocument` can
|
||||
also ask the bridge to open a rule's documentation externally.
|
||||
|
||||
### Multiple language servers
|
||||
|
||||
Helix can run the bridge alongside a semantic VHDL server such as `vhdl_ls`:
|
||||
|
||||
```toml
|
||||
[language-server.vhdl_ls]
|
||||
command = "vhdl_ls"
|
||||
args = ["-l", "/usr/local/lib/vhdl_libraries"]
|
||||
|
||||
[[language]]
|
||||
name = "vhdl"
|
||||
file-types = ["vhd", "vhdl"]
|
||||
language-servers = ["vhdl_ls", "vsg_bridge_ls"]
|
||||
auto-format = false
|
||||
```
|
||||
|
||||
Both servers may answer the same hover request. In Helix's hover popup, use
|
||||
`Alt+n` for the next result and `Alt+p` for the previous result. The bridge may
|
||||
appear first regardless of the order in `language-servers`; treat the popup as
|
||||
a set of results rather than relying on response order.
|
||||
|
||||
If VSG hover is unwanted, place this in `vsg-bridge-ls.toml`:
|
||||
|
||||
```toml
|
||||
disable_hover = true
|
||||
```
|
||||
|
||||
The equivalent command-line option is `--disable-hover`. Diagnostics,
|
||||
formatting, and code actions remain available; only hover is disabled.
|
||||
|
||||
With `--experimental-rule-fix`, the code-action menu immediately offers a Quick
|
||||
Fix for each fixable VSG rule on the diagnosed line. Building the menu does not
|
||||
run VSG; selecting one action runs one VSG process against the current
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ allow_browser_action = false
|
|||
experimental_rule_fix = false
|
||||
experimental_multi_rule_line_fix = false
|
||||
debug_mode = false
|
||||
disable_hover = false
|
||||
strict_diagnostic_severity = false
|
||||
```
|
||||
|
||||
|
|
@ -35,6 +36,11 @@ action asks the LSP client to open an external HTTPS URL. It is equivalent to
|
|||
the explicit `--allow-browser-action` flag. Documentation URLs remain visible
|
||||
in diagnostics and hover when browser actions are disabled.
|
||||
|
||||
`disable_hover` is useful when another language server should own hover
|
||||
presentation. Setting it to `true` stops the bridge from advertising or
|
||||
returning hover text without disabling diagnostics, formatting, or actions.
|
||||
It is equivalent to `--disable-hover`.
|
||||
|
||||
`strict_diagnostic_severity` is disabled by default. In the default
|
||||
editor-friendly mode, VSG `error` findings become LSP warnings and VSG
|
||||
`warning` findings become LSP information; informational findings remain
|
||||
|
|
|
|||
35
src/lib.rs
35
src/lib.rs
|
|
@ -54,6 +54,9 @@ pub struct Options {
|
|||
/// Adds runtime state to hover and offers a fallback action.
|
||||
#[arg(long)]
|
||||
pub debug_mode: bool,
|
||||
/// Disables VSG hover responses for multi-server editor setups.
|
||||
#[arg(long)]
|
||||
pub disable_hover: bool,
|
||||
/// Preserves VSG lint severities instead of using editor-friendly levels.
|
||||
#[arg(long)]
|
||||
pub strict_diagnostic_severity: bool,
|
||||
|
|
@ -75,6 +78,8 @@ struct GeneratedFileOptions<'a> {
|
|||
experimental_multi_rule_line_fix: bool,
|
||||
/// Whether runtime debug information is exposed.
|
||||
debug_mode: bool,
|
||||
/// Whether VSG hover responses are disabled.
|
||||
disable_hover: bool,
|
||||
/// Whether VSG lint severities map directly to LSP severities.
|
||||
strict_diagnostic_severity: bool,
|
||||
}
|
||||
|
|
@ -93,6 +98,8 @@ struct FileOptions {
|
|||
experimental_multi_rule_line_fix: Option<bool>,
|
||||
/// Whether runtime debug information is exposed.
|
||||
debug_mode: Option<bool>,
|
||||
/// Whether VSG hover responses are disabled.
|
||||
disable_hover: Option<bool>,
|
||||
/// Whether VSG lint severities map directly to LSP severities.
|
||||
strict_diagnostic_severity: Option<bool>,
|
||||
}
|
||||
|
|
@ -115,6 +122,9 @@ impl FileOptions {
|
|||
if higher.debug_mode.is_some() {
|
||||
self.debug_mode = higher.debug_mode;
|
||||
}
|
||||
if higher.disable_hover.is_some() {
|
||||
self.disable_hover = higher.disable_hover;
|
||||
}
|
||||
if higher.strict_diagnostic_severity.is_some() {
|
||||
self.strict_diagnostic_severity = higher.strict_diagnostic_severity;
|
||||
}
|
||||
|
|
@ -156,6 +166,7 @@ impl Options {
|
|||
experimental_multi_rule_line_fix: self.experimental_multi_rule_line_fix
|
||||
|| file.experimental_multi_rule_line_fix.unwrap_or(false),
|
||||
debug_mode: self.debug_mode || file.debug_mode.unwrap_or(false),
|
||||
disable_hover: self.disable_hover || file.disable_hover.unwrap_or(false),
|
||||
strict_diagnostic_severity: self.strict_diagnostic_severity
|
||||
|| file.strict_diagnostic_severity.unwrap_or(false),
|
||||
write_config: self.write_config,
|
||||
|
|
@ -179,6 +190,7 @@ impl Options {
|
|||
experimental_rule_fix: self.experimental_rule_fix,
|
||||
experimental_multi_rule_line_fix: self.experimental_multi_rule_line_fix,
|
||||
debug_mode: self.debug_mode,
|
||||
disable_hover: self.disable_hover,
|
||||
strict_diagnostic_severity: self.strict_diagnostic_severity,
|
||||
};
|
||||
let body = toml::to_string_pretty(&configuration)
|
||||
|
|
@ -257,6 +269,7 @@ where
|
|||
.with_experimental_rule_fix(options.experimental_rule_fix)
|
||||
.with_experimental_multi_rule_line_fix(options.experimental_multi_rule_line_fix)
|
||||
.with_debug_mode(options.debug_mode)
|
||||
.with_hover_disabled(options.disable_hover)
|
||||
.with_strict_diagnostic_severity(options.strict_diagnostic_severity)
|
||||
});
|
||||
|
||||
|
|
@ -374,6 +387,7 @@ mod tests {
|
|||
assert!(!options.experimental_rule_fix);
|
||||
assert!(!options.experimental_multi_rule_line_fix);
|
||||
assert!(!options.debug_mode);
|
||||
assert!(!options.disable_hover);
|
||||
assert!(!options.strict_diagnostic_severity);
|
||||
assert!(!options.write_config);
|
||||
}
|
||||
|
|
@ -382,9 +396,9 @@ mod tests {
|
|||
#[test]
|
||||
fn version_includes_source_revision() {
|
||||
assert_eq!(Options::command().get_version(), Some(VERSION));
|
||||
assert!(VERSION.starts_with("0.3.5-rc.1+git."));
|
||||
assert!(VERSION.starts_with("0.3.6-rc.1+git."));
|
||||
assert!(VERSION
|
||||
.strip_prefix("0.3.5-rc.1+git.")
|
||||
.strip_prefix("0.3.6-rc.1+git.")
|
||||
.is_some_and(|revision| revision == "unknown"
|
||||
|| (revision.len() == 8 && revision.bytes().all(|byte| byte.is_ascii_hexdigit()))));
|
||||
}
|
||||
|
|
@ -411,6 +425,7 @@ vsg_configuration = ["user.yaml"]
|
|||
allow_browser_action = true
|
||||
experimental_rule_fix = true
|
||||
debug_mode = true
|
||||
disable_hover = true
|
||||
strict_diagnostic_severity = true
|
||||
"#,
|
||||
)
|
||||
|
|
@ -422,6 +437,7 @@ allow_browser_action = false
|
|||
experimental_rule_fix = false
|
||||
experimental_multi_rule_line_fix = true
|
||||
debug_mode = false
|
||||
disable_hover = false
|
||||
strict_diagnostic_severity = false
|
||||
"#,
|
||||
)
|
||||
|
|
@ -436,6 +452,7 @@ strict_diagnostic_severity = false
|
|||
assert!(!from_files.experimental_rule_fix);
|
||||
assert!(from_files.experimental_multi_rule_line_fix);
|
||||
assert!(!from_files.debug_mode);
|
||||
assert!(!from_files.disable_hover);
|
||||
assert!(!from_files.strict_diagnostic_severity);
|
||||
|
||||
let from_cli = Options::try_parse_from([
|
||||
|
|
@ -445,6 +462,7 @@ strict_diagnostic_severity = false
|
|||
"--allow-browser-action",
|
||||
"--experimental-rule-fix",
|
||||
"--debug-mode",
|
||||
"--disable-hover",
|
||||
"--strict-diagnostic-severity",
|
||||
])
|
||||
.expect("explicit CLI")
|
||||
|
|
@ -455,6 +473,7 @@ strict_diagnostic_severity = false
|
|||
assert!(from_cli.experimental_rule_fix);
|
||||
assert!(from_cli.experimental_multi_rule_line_fix);
|
||||
assert!(from_cli.debug_mode);
|
||||
assert!(from_cli.disable_hover);
|
||||
assert!(from_cli.strict_diagnostic_severity);
|
||||
}
|
||||
|
||||
|
|
@ -502,6 +521,15 @@ strict_diagnostic_severity = false
|
|||
assert!(options.debug_mode);
|
||||
}
|
||||
|
||||
/// Hover suppression requires an explicit runtime opt-in.
|
||||
#[test]
|
||||
fn parses_disable_hover_flag() {
|
||||
let options = Options::try_parse_from(["vsg-bridge-ls", "--disable-hover"])
|
||||
.expect("hover flag is valid");
|
||||
|
||||
assert!(options.disable_hover);
|
||||
}
|
||||
|
||||
/// Exact VSG severity mapping requires an explicit runtime opt-in.
|
||||
#[test]
|
||||
fn parses_strict_diagnostic_severity_flag() {
|
||||
|
|
@ -523,6 +551,7 @@ strict_diagnostic_severity = false
|
|||
"rules one.yaml",
|
||||
"--allow-browser-action",
|
||||
"--experimental-rule-fix",
|
||||
"--disable-hover",
|
||||
"--strict-diagnostic-severity",
|
||||
])
|
||||
.expect("configuration generation arguments are valid");
|
||||
|
|
@ -542,6 +571,7 @@ strict_diagnostic_severity = false
|
|||
assert_eq!(generated.experimental_rule_fix, Some(true));
|
||||
assert_eq!(generated.experimental_multi_rule_line_fix, Some(false));
|
||||
assert_eq!(generated.debug_mode, Some(false));
|
||||
assert_eq!(generated.disable_hover, Some(true));
|
||||
assert_eq!(generated.strict_diagnostic_severity, Some(true));
|
||||
|
||||
let error = options
|
||||
|
|
@ -564,6 +594,7 @@ strict_diagnostic_severity = false
|
|||
experimental_rule_fix: false,
|
||||
experimental_multi_rule_line_fix: false,
|
||||
debug_mode: false,
|
||||
disable_hover: false,
|
||||
strict_diagnostic_severity: false,
|
||||
write_config: false,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -104,6 +104,8 @@ pub struct Backend {
|
|||
experimental_multi_rule_line_fix: bool,
|
||||
/// Enables the opt-in runtime debug-information action.
|
||||
debug_mode: bool,
|
||||
/// Suppresses hover capability and responses for multi-server setups.
|
||||
disable_hover: bool,
|
||||
/// Preserves VSG lint severities instead of using editor-friendly levels.
|
||||
strict_diagnostic_severity: bool,
|
||||
/// Last persistent VSG failure already shown to the user.
|
||||
|
|
@ -124,6 +126,7 @@ impl Backend {
|
|||
experimental_rule_fix: false,
|
||||
experimental_multi_rule_line_fix: false,
|
||||
debug_mode: false,
|
||||
disable_hover: false,
|
||||
strict_diagnostic_severity: false,
|
||||
last_vsg_error: Mutex::new(None),
|
||||
}
|
||||
|
|
@ -157,6 +160,13 @@ impl Backend {
|
|||
self
|
||||
}
|
||||
|
||||
/// Enables or disables all VSG hover presentation.
|
||||
#[must_use]
|
||||
pub fn with_hover_disabled(mut self, disabled: bool) -> Self {
|
||||
self.disable_hover = disabled;
|
||||
self
|
||||
}
|
||||
|
||||
/// Enables or disables exact VSG-to-LSP diagnostic severity mapping.
|
||||
#[must_use]
|
||||
pub fn with_strict_diagnostic_severity(mut self, enabled: bool) -> Self {
|
||||
|
|
@ -213,6 +223,7 @@ impl Backend {
|
|||
"documents": document_state,
|
||||
"modes": {
|
||||
"debug": self.debug_mode,
|
||||
"disable_hover": self.disable_hover,
|
||||
"experimental_rule_fix": self.experimental_rule_fix,
|
||||
"experimental_multi_rule_line_fix": self.experimental_multi_rule_line_fix,
|
||||
"strict_diagnostic_severity": self.strict_diagnostic_severity,
|
||||
|
|
@ -462,7 +473,8 @@ impl LanguageServer for Backend {
|
|||
..TextDocumentSyncOptions::default()
|
||||
},
|
||||
)),
|
||||
hover_provider: Some(HoverProviderCapability::Simple(true)),
|
||||
hover_provider: (!self.disable_hover)
|
||||
.then_some(HoverProviderCapability::Simple(true)),
|
||||
document_formatting_provider: Some(OneOf::Left(true)),
|
||||
code_action_provider: Some(CodeActionProviderCapability::Options(
|
||||
CodeActionOptions {
|
||||
|
|
@ -502,6 +514,9 @@ impl LanguageServer for Backend {
|
|||
}
|
||||
|
||||
async fn hover(&self, parameters: HoverParams) -> Result<Option<Hover>> {
|
||||
if self.disable_hover {
|
||||
return Ok(None);
|
||||
}
|
||||
let text_document_position = parameters.text_document_position_params;
|
||||
let Some(document) = self
|
||||
.snapshot(&text_document_position.text_document.uri)
|
||||
|
|
@ -1211,6 +1226,45 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
/// Disabled hover is neither advertised nor returned if a client still requests it.
|
||||
#[tokio::test]
|
||||
async fn disables_hover_for_multi_server_setups() {
|
||||
let runner = Arc::new(MockRunner::successful(ONE_DIAGNOSTIC));
|
||||
let (mut service, mut socket) = LspService::new(move |client| {
|
||||
Backend::new(client, runner.clone(), Vec::new()).with_hover_disabled(true)
|
||||
});
|
||||
let initialized = initialize(&mut service).await;
|
||||
let initialized = serde_json::to_value(initialized).expect("serialize initialization");
|
||||
assert!(initialized["result"]["capabilities"]["hoverProvider"].is_null());
|
||||
|
||||
open_document(
|
||||
&mut service,
|
||||
&mut socket,
|
||||
json!({"textDocument": {
|
||||
"uri": "file:///tmp/example.vhd", "languageId": "vhdl",
|
||||
"version": 1, "text": "entity demo is"
|
||||
}}),
|
||||
)
|
||||
.await;
|
||||
let request = Request::build("textDocument/hover")
|
||||
.params(json!({
|
||||
"textDocument": {"uri": "file:///tmp/example.vhd"},
|
||||
"position": {"line": 0, "character": 2}
|
||||
}))
|
||||
.id(17)
|
||||
.finish();
|
||||
let response = service
|
||||
.ready()
|
||||
.await
|
||||
.expect("service ready")
|
||||
.call(request)
|
||||
.await
|
||||
.expect("hover call")
|
||||
.expect("hover response");
|
||||
let response = serde_json::to_value(response).expect("serialize response");
|
||||
assert!(response["result"].is_null());
|
||||
}
|
||||
|
||||
/// Client browser support alone does not opt in to external navigation.
|
||||
#[tokio::test]
|
||||
async fn omits_documentation_command_without_permission() {
|
||||
|
|
@ -1431,8 +1485,9 @@ mod tests {
|
|||
|
||||
assert!(report["bridge"]["version"]
|
||||
.as_str()
|
||||
.is_some_and(|version| version.starts_with("0.3.5-rc.1+git.")));
|
||||
.is_some_and(|version| version.starts_with("0.3.6-rc.1+git.")));
|
||||
assert_eq!(report["modes"]["debug"], true);
|
||||
assert_eq!(report["modes"]["disable_hover"], false);
|
||||
assert_eq!(report["modes"]["experimental_rule_fix"], true);
|
||||
assert_eq!(report["modes"]["experimental_multi_rule_line_fix"], true);
|
||||
assert_eq!(report["modes"]["strict_diagnostic_severity"], false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue