Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ impl ProtoLanguageServer {
Box::pin(async move { Ok(response) })
}

pub(super) fn shutdown(
&mut self,
_params: (),
) -> BoxFuture<'static, Result<(), ResponseError>> {
info!("Received shutdown request");
self.shutdown_received = true;
Box::pin(async move { Ok(()) })
}

pub(super) fn hover(
&mut self,
param: HoverParams,
Expand Down Expand Up @@ -564,6 +573,16 @@ impl ProtoLanguageServer {
}
ControlFlow::Continue(())
}

pub(super) fn exit(&mut self, _params: ()) -> ControlFlow<async_lsp::Result<()>> {
if self.shutdown_received {
info!("Received exit notification after shutdown, exiting with code 0");
std::process::exit(0);
} else {
warn!("Received exit notification without shutdown, exiting with code 1");
std::process::exit(1);
}
}
}

/// Parse include_paths from initialization options
Expand Down
8 changes: 6 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use async_lsp::{
NumberOrString, ProgressParams, ProgressParamsValue,
notification::{
DidChangeTextDocument, DidCreateFiles, DidDeleteFiles, DidOpenTextDocument,
DidRenameFiles, DidSaveTextDocument,
DidRenameFiles, DidSaveTextDocument, Exit,
},
request::{
Completion, DocumentSymbolRequest, Formatting, GotoDefinition, HoverRequest,
Initialize, PrepareRenameRequest, RangeFormatting, References, Rename,
Initialize, PrepareRenameRequest, RangeFormatting, References, Rename, Shutdown,
WorkspaceSymbolRequest,
},
},
Expand All @@ -29,6 +29,7 @@ pub struct ProtoLanguageServer {
pub counter: i32,
pub state: ProtoLanguageState,
pub configs: WorkspaceProtoConfigs,
pub shutdown_received: bool,
}

impl ProtoLanguageServer {
Expand All @@ -42,6 +43,7 @@ impl ProtoLanguageServer {
counter: 0,
state: ProtoLanguageState::new(),
configs: WorkspaceProtoConfigs::new(cli_include_paths, fallback_include_path),
shutdown_received: false,
});

router.event::<TickEvent>(|st, _| {
Expand All @@ -57,6 +59,7 @@ impl ProtoLanguageServer {

// Handling request
router.request::<Initialize, _>(|st, params| st.initialize(params));
router.request::<Shutdown, _>(|st, params| st.shutdown(params));
router.request::<HoverRequest, _>(|st, params| st.hover(params));
router.request::<Completion, _>(|st, params| st.completion(params));
router.request::<PrepareRenameRequest, _>(|st, params| st.prepare_rename(params));
Expand All @@ -75,6 +78,7 @@ impl ProtoLanguageServer {
router.notification::<DidCreateFiles>(|st, params| st.did_create_files(params));
router.notification::<DidRenameFiles>(|st, params| st.did_rename_files(params));
router.notification::<DidDeleteFiles>(|st, params| st.did_delete_files(params));
router.notification::<Exit>(|st, params| st.exit(params));

router
}
Expand Down
12 changes: 6 additions & 6 deletions src/workspace/workspace_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ mod test {
"file://{}/src/workspace/input/a.proto",
current_dir.to_str().unwrap()
)
.parse()
.unwrap();
.parse()
.unwrap();
let b_uri = format!(
"file://{}/src/workspace/input/b.proto",
current_dir.to_str().unwrap()
)
.parse()
.unwrap();
.parse()
.unwrap();
let c_uri = format!(
"file://{}/src/workspace/input/c.proto",
current_dir.to_str().unwrap()
)
.parse()
.unwrap();
.parse()
.unwrap();

let a = include_str!("input/a.proto");
let b = include_str!("input/b.proto");
Expand Down