Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.DS_Store
.AppleDouble
.LSOverride
justfile

# Icon must end with two \r
Icon
Expand Down
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.cargo.target": "wasm32-wasi",
"rust-analyzer.rustfmt.overrideCommand": ["cargo", "+nightly", "fmt"]
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.cargo.target": "wasm32-wasi",
"rust-analyzer.rustfmt.overrideCommand": ["rustfmt", "+nightly"]
}
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ serde = { version = "1.0", features = ["derive"] }
[target.'cfg(target_os = "wasi")'.dependencies.volt]
package = "lapce-plugin"
git = "https://github.com/lapce/lapce-plugin-rust.git"
# git = "https://github.com/panekj/lapce-plugin-rust.git"
# branch = "volt"
# path = "../../lapce-plugin-rust"
rev = "1657b855016c6bb50953e74eba4d079bf3173d63"

[profile.release]
opt-level = 3
Expand Down
36 changes: 17 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use serde_json::Value;
use volt::{
psp_types::{
lsp_types::{
request::Initialize, DocumentFilter, DocumentSelector, InitializeParams, MessageType,
Url,
request::Initialize, DocumentFilter, DocumentSelector, InitializeParams,
InitializeResult, Url,
},
Request,
},
Expand Down Expand Up @@ -47,7 +47,10 @@ macro_rules! string {
String::from($s)
};
}
fn initialize(params: InitializeParams) -> Result<()> {

type LspParams = (Url, Vec<String>, Vec<DocumentFilter>, Option<Value>);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as a struct so that each of the values can have names.


fn calculate_lsp_params(params: InitializeParams) -> Result<LspParams> {
let document_selector: DocumentSelector = vec![DocumentFilter {
language: Some(string!("go")),
pattern: Some(string!("**.go")),
Expand Down Expand Up @@ -77,8 +80,7 @@ fn initialize(params: InitializeParams) -> Result<()> {
if let Some(server_path) = server_path.as_str() {
if !server_path.is_empty() {
let url = Url::parse(&format!("urn:{server_path}"))?;
PLUGIN_RPC.start_lsp(url, server_args, document_selector, options);
return Ok(());
return Ok((url, server_args, document_selector, options));
}
}
}
Expand Down Expand Up @@ -127,27 +129,23 @@ fn initialize(params: InitializeParams) -> Result<()> {

let server_uri = Url::parse(&format!("urn:{}", server_path.display()))?;

PLUGIN_RPC.start_lsp(dbg!(server_uri), server_args, document_selector, options);

Ok(())
Ok((server_uri, server_args, document_selector, options))
}

impl LapcePlugin for State {
fn handle_request(&mut self, _id: u64, method: String, params: Value) {
fn handle_request(&mut self, id: u64, method: String, params: Value) {
#[allow(clippy::single_match)]
match method.as_str() {
Initialize::METHOD => {
let params: InitializeParams = serde_json::from_value(params).unwrap();
if let Err(e) = initialize(params) {
PLUGIN_RPC.window_show_message(
MessageType::ERROR,
format!("plugin returned with error: {e}"),
);
} else {
PLUGIN_RPC.window_log_message(
MessageType::INFO,
string!("plugin finished execution"),
);
match calculate_lsp_params(params) {
Ok((uri, args, filters, options)) => {
PLUGIN_RPC.start_lsp(uri, args, filters, options).unwrap();
PLUGIN_RPC
.host_success(id, InitializeResult::default())
.unwrap();
}
Err(err) => PLUGIN_RPC.host_error(id, err.to_string()).unwrap(),
}
}
_ => {}
Expand Down