完成 CodeLens 的支持
This commit is contained in:
parent
b01ff8e371
commit
348214e42d
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ build.bat
|
|||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.cache
|
.cache
|
||||||
|
deploy.*
|
27
src/code_lens/mod.rs
Normal file
27
src/code_lens/mod.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use crate::server::LSPServer;
|
||||||
|
use crate::utils::*;
|
||||||
|
#[allow(unused)]
|
||||||
|
use log::info;
|
||||||
|
use tower_lsp::lsp_types::*;
|
||||||
|
|
||||||
|
mod sv;
|
||||||
|
mod vhdl;
|
||||||
|
|
||||||
|
impl LSPServer {
|
||||||
|
pub fn code_lens(&self, params: CodeLensParams) -> Option<Vec<CodeLens>> {
|
||||||
|
let language_id = get_language_id_by_uri(¶ms.text_document.uri);
|
||||||
|
match language_id.as_str() {
|
||||||
|
"vhdl" => vhdl::code_lens(
|
||||||
|
self,
|
||||||
|
¶ms
|
||||||
|
),
|
||||||
|
|
||||||
|
"verilog" | "systemverilog" => sv::code_lens(
|
||||||
|
self,
|
||||||
|
¶ms
|
||||||
|
),
|
||||||
|
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
src/code_lens/sv.rs
Normal file
57
src/code_lens/sv.rs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
use std::{path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
|
use crate::server::LSPServer;
|
||||||
|
#[allow(unused)]
|
||||||
|
use log::info;
|
||||||
|
use tower_lsp::lsp_types::*;
|
||||||
|
|
||||||
|
use super::to_escape_path;
|
||||||
|
|
||||||
|
pub fn code_lens(
|
||||||
|
#[allow(unused)]
|
||||||
|
server: &LSPServer,
|
||||||
|
#[allow(unused)]
|
||||||
|
params: &CodeLensParams
|
||||||
|
) -> Option<Vec<CodeLens>> {
|
||||||
|
let hdl_param = server.srcs.hdl_param.clone();
|
||||||
|
let uri = ¶ms.text_document.uri;
|
||||||
|
|
||||||
|
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
|
let pathbuf = PathBuf::from_str(uri.path()).unwrap();
|
||||||
|
let pathbuf = to_escape_path(&pathbuf);
|
||||||
|
let path_string = pathbuf.to_str().unwrap();
|
||||||
|
|
||||||
|
info!("[code_lens] {}", path_string);
|
||||||
|
|
||||||
|
let mut code_lens_array = Vec::<CodeLens>::new();
|
||||||
|
if let Some(hdl_file) = path_to_hdl_file.get(path_string) {
|
||||||
|
for module in &hdl_file.fast.content {
|
||||||
|
// 此处只有 name 和 path 有用
|
||||||
|
let module_data_item: serde_json::Value = serde_json::json!({
|
||||||
|
"icon": "",
|
||||||
|
"name": module.name.to_string(),
|
||||||
|
"type": "",
|
||||||
|
"doFastFileType": "common",
|
||||||
|
"range": null,
|
||||||
|
"path": path_string.to_string(),
|
||||||
|
"parent": null
|
||||||
|
});
|
||||||
|
|
||||||
|
let command = Command {
|
||||||
|
title: "Simulate".to_string(),
|
||||||
|
command: "digital-ide.tool.icarus.simulateFile".to_string(),
|
||||||
|
arguments: Some(vec![module_data_item])
|
||||||
|
};
|
||||||
|
let code_lens = CodeLens {
|
||||||
|
range: module.range.to_lsp_range(),
|
||||||
|
command: Some(command),
|
||||||
|
data: None
|
||||||
|
};
|
||||||
|
code_lens_array.push(code_lens);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Some(code_lens_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
14
src/code_lens/vhdl.rs
Normal file
14
src/code_lens/vhdl.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
use crate::server::LSPServer;
|
||||||
|
#[allow(unused)]
|
||||||
|
use log::info;
|
||||||
|
use tower_lsp::lsp_types::*;
|
||||||
|
|
||||||
|
pub fn code_lens(
|
||||||
|
#[allow(unused)]
|
||||||
|
server: &LSPServer,
|
||||||
|
#[allow(unused)]
|
||||||
|
params: &CodeLensParams
|
||||||
|
) -> Option<Vec<CodeLens>> {
|
||||||
|
None
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
use std::{collections::HashMap, path::PathBuf, str::FromStr};
|
use std::{collections::HashMap, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use crate::{core, server::LSPServer, sources::LSPSupport};
|
use crate::{core, server::LSPServer};
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
use log::info;
|
use log::info;
|
||||||
use ropey::Rope;
|
use ropey::Rope;
|
||||||
|
@ -21,6 +21,9 @@ pub mod document_highlight;
|
|||||||
// 内部提示
|
// 内部提示
|
||||||
pub mod inlay_hint;
|
pub mod inlay_hint;
|
||||||
|
|
||||||
|
// code lens 按钮
|
||||||
|
pub mod code_lens;
|
||||||
|
|
||||||
// 诊断
|
// 诊断
|
||||||
pub mod diagnostics;
|
pub mod diagnostics;
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ mod hover;
|
|||||||
mod document_symbol;
|
mod document_symbol;
|
||||||
mod document_highlight;
|
mod document_highlight;
|
||||||
mod inlay_hint;
|
mod inlay_hint;
|
||||||
|
mod code_lens;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod diagnostics;
|
mod diagnostics;
|
||||||
mod format;
|
mod format;
|
||||||
|
@ -258,6 +258,7 @@ impl LanguageServer for Backend {
|
|||||||
document_symbol_provider: Some(OneOf::Left(true)),
|
document_symbol_provider: Some(OneOf::Left(true)),
|
||||||
document_highlight_provider: Some(OneOf::Left(true)),
|
document_highlight_provider: Some(OneOf::Left(true)),
|
||||||
workspace: Some(workspace),
|
workspace: Some(workspace),
|
||||||
|
code_lens_provider: Some(CodeLensOptions { resolve_provider: Some(true) }),
|
||||||
..ServerCapabilities::default()
|
..ServerCapabilities::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -370,4 +371,11 @@ impl LanguageServer for Backend {
|
|||||||
) -> Result<Option<Vec<InlayHint>>> {
|
) -> Result<Option<Vec<InlayHint>>> {
|
||||||
Ok(self.server.inlay_hint(params))
|
Ok(self.server.inlay_hint(params))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn code_lens(
|
||||||
|
&self,
|
||||||
|
params: CodeLensParams
|
||||||
|
) -> Result<Option<Vec<CodeLens>>> {
|
||||||
|
Ok(self.server.code_lens(params))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,6 +447,7 @@ impl Sources {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn get_lsp_configuration_string_value(&self, name: &str) -> Option<String> {
|
pub fn get_lsp_configuration_string_value(&self, name: &str) -> Option<String> {
|
||||||
let lsp_configuration = self.lsp_configuration.read().unwrap();
|
let lsp_configuration = self.lsp_configuration.read().unwrap();
|
||||||
if let Some(Value::String(value)) = lsp_configuration.get(name) {
|
if let Some(Value::String(value)) = lsp_configuration.get(name) {
|
||||||
@ -455,6 +456,7 @@ impl Sources {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn get_lsp_configuration_i64_value(&self, name: &str) -> Option<i64> {
|
pub fn get_lsp_configuration_i64_value(&self, name: &str) -> Option<i64> {
|
||||||
let lsp_configuration = self.lsp_configuration.read().unwrap();
|
let lsp_configuration = self.lsp_configuration.read().unwrap();
|
||||||
if let Some(Value::Number(number)) = lsp_configuration.get(name) {
|
if let Some(Value::Number(number)) = lsp_configuration.get(name) {
|
||||||
@ -463,6 +465,7 @@ impl Sources {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn get_lsp_configuration_bool_value(&self, name: &str) -> Option<bool> {
|
pub fn get_lsp_configuration_bool_value(&self, name: &str) -> Option<bool> {
|
||||||
let lsp_configuration = self.lsp_configuration.read().unwrap();
|
let lsp_configuration = self.lsp_configuration.read().unwrap();
|
||||||
if let Some(Value::Bool(value)) = lsp_configuration.get(name) {
|
if let Some(Value::Bool(value)) = lsp_configuration.get(name) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user