Skip to content

Commit

Permalink
feat: get request params
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 26, 2022
1 parent 9f5d39c commit 7748411
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bsp-server/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum Request {
}

impl Request {
/// Get request method
pub fn method(&self) -> &'static str {
use Request::*;
match self {
Expand All @@ -73,6 +74,7 @@ impl Request {
}
}

/// Get request id
pub fn id(&self) -> &RequestId {
use Request::*;
match self {
Expand All @@ -93,6 +95,28 @@ impl Request {
| Custom(id, _, _) => id,
}
}

/// Get request params
pub fn params(&self) -> anyhow::Result<Value> {
use Request::*;
let value = match self {
Shutdown(_) | WorkspaceBuildTargets(_) | WorkspaceReload(_) => return Ok(Value::Null),
InitializeBuild(_, ref params) => serde_json::to_value(params),
BuildTargetDependencyModules(_, ref params) => serde_json::to_value(params),
DebugSessionStart(_, ref params) => serde_json::to_value(params),
BuildTargetSources(_, ref params) => serde_json::to_value(params),
TextDocumentInverseSources(_, ref params) => serde_json::to_value(params),
BuildTargetDependencySources(_, ref params) => serde_json::to_value(params),
BuildTargetResources(_, ref params) => serde_json::to_value(params),
BuildTargetRun(_, ref params) => serde_json::to_value(params),
BuildTargetCompile(_, ref params) => serde_json::to_value(params),
BuildTargetTest(_, ref params) => serde_json::to_value(params),
BuildTargetCleanCache(_, ref params) => serde_json::to_value(params),
Custom(_, ref params, _) => serde_json::to_value(params),
};

Ok(value?)
}
}

impl From<Request> for Message {
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "stable"

0 comments on commit 7748411

Please sign in to comment.