Adds some ressources and works on pattern matching

This commit is contained in:
Dandaedre 2024-11-20 10:49:14 -06:00
parent 2876363606
commit 614d95d8ad
2 changed files with 42 additions and 29 deletions

View File

@ -24,22 +24,12 @@ command = "vsg_bridge_ls"
[ [language]]
name = "vhdl"
# scope = "source.blarg"
# injection-regex = "rs|rust"
file-types = ["vhd", "vhdl"]
# roots = ["Cargo.toml", "Cargo.lock"]
# shebangs = ["rust-script", "cargo"]
# auto-format = false
# comment-tokens = ["//", "///", "//!"]
# block-comment-tokens = [
# { start = "/*", end = "*/" },
# { start = "/**", end = "*/" },
# { start = "/*!", end = "*/" },
# ]
language-servers = [ "vsg_bridge_ls" ]
# indent = { tab-width = 4, unit = " " }
# persistent-diagnostic-sources = ["rustc", "clippy"]
```
# Documentation
[Tower-lsp](https://github.com/ebkalderon/tower-lsp/blob/master/examples/stdio.rs)
[VSG Github](https://github.com/jeremiah-c-leary/vhdl-style-guide)
[VSG Docs](https://vhdl-style-guide.readthedocs.io/en/latest/editor_integration/vscode.html)
[Lsp Specs](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/)

View File

@ -1,8 +1,6 @@
use once_cell::sync::OnceCell;
use regex::Regex;
use anyhow::{anyhow, Context};
use serde_json::Value;
use std::process::Command;
use tower_lsp::jsonrpc::{self, Result};
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer, LspService, Server};
@ -20,7 +18,10 @@ struct Backend {
#[tower_lsp::async_trait]
impl LanguageServer for Backend {
async fn initialize(&self, _: InitializeParams) -> Result<InitializeResult> {
async fn initialize(
&self,
_: InitializeParams,
) -> Result<InitializeResult, tower_lsp::jsonrpc::Error> {
Ok(InitializeResult {
server_info: None,
capabilities: ServerCapabilities {
@ -69,7 +70,7 @@ impl LanguageServer for Backend {
.await;
}
async fn shutdown(&self) -> Result<()> {
async fn shutdown(&self) -> Result<(), tower_lsp::jsonrpc::Error> {
Ok(())
}
@ -91,7 +92,10 @@ impl LanguageServer for Backend {
// .await;
}
async fn execute_command(&self, _: ExecuteCommandParams) -> Result<Option<Value>> {
async fn execute_command(
&self,
_: ExecuteCommandParams,
) -> Result<Option<Value>, tower_lsp::jsonrpc::Error> {
// self.client
// .log_message(MessageType::INFO, "command executed!")
// .await;
@ -118,7 +122,6 @@ impl LanguageServer for Backend {
}
async fn did_save(&self, p: DidSaveTextDocumentParams) {
let reg = regex!(r"^ ([^\\s]*_\\d*)\\s*. ([^\\s]*)\\s*.\\s*([^\\s]*) . (.*)$");
self.client
.log_message(MessageType::INFO, "file saved!")
.await;
@ -143,7 +146,10 @@ impl LanguageServer for Backend {
// .await;
}
async fn completion(&self, _: CompletionParams) -> Result<Option<CompletionResponse>> {
async fn completion(
&self,
_: CompletionParams,
) -> Result<Option<CompletionResponse>, tower_lsp::jsonrpc::Error> {
// Ok(Some(CompletionResponse::Array(vec![
// CompletionItem::new_simple("Hello".to_string(), "Some detail".to_string()),
// CompletionItem::new_simple("Bye".to_string(), "More detail".to_string()),
@ -152,19 +158,36 @@ impl LanguageServer for Backend {
}
}
async fn find_diagnostics_for_file(uri: Url) -> Result<Vec<Diagnostic>> {
let output = Command::new("ls")
// .arg("file.txt")
async fn find_diagnostics_for_file(uri: Url) -> Result<Vec<Diagnostic>, anyhow::Error> {
let reg = regex!(r"^ ([^\s]*_\d*)\s*. ([^\s]*)\s*.\s*([^\s]*) . (.*)$");
let v = &Command::new("vsg")
.arg("-f")
.arg(uri.as_str())
.output()
.unwrap();
.context("running vsg linter")?
.stdout;
let output = String::from_utf8_lossy(v);
let mut matches = reg.captures_iter(&output);
// for m in matches {
// let rule = m.get(1);
// let severity = m.get(2);
// let line = m.get(3);
// let solution = m.get(4);
// }
let m = matches.next().ok_or_else(|| anyhow!("Welp..."))?;
let rule = m.get(1);
let severity = m.get(2);
let line = m.get(3);
let solution = m.get(4);
let show = format!("{:?} {:?} {:?} {:?}", rule, severity, line, solution);
let range = make_range(1);
let d = Diagnostic {
range,
severity: Some(DiagnosticSeverity::WARNING), // Everything is a warning
code: Some(NumberOrString::String(
String::from_utf8_lossy(&output.stdout).into(),
)), // The important second part
// code_description: Some(NumberOrString::String(output.stdout.to_string())),
code: Some(NumberOrString::String(show)), // The important second part
code_description: Some(CodeDescription { href: uri.clone() }),
source: Some("Source ?".into()),
message: "El message".to_string(),