mirror of
https://github.com/oxalica/nil.git
synced 2024-10-27 12:30:52 +03:00
Add LSP extension to reload flake states
This commit is contained in:
parent
ddb446aa1c
commit
5700b00872
@ -1,3 +1,4 @@
|
||||
use lsp_types::notification::Notification;
|
||||
use lsp_types::request::Request;
|
||||
|
||||
/// <https://github.com/microsoft/language-server-protocol/issues/1002>
|
||||
@ -8,3 +9,10 @@ impl Request for ParentModule {
|
||||
type Result = Option<lsp_types::GotoDefinitionResponse>;
|
||||
const METHOD: &'static str = "experimental/parentModule";
|
||||
}
|
||||
|
||||
pub enum ReloadFlake {}
|
||||
|
||||
impl Notification for ReloadFlake {
|
||||
type Params = ();
|
||||
const METHOD: &'static str = "nil/reloadFlake";
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ impl Server {
|
||||
// > In former implementations clients pushed file events without the server actively asking for it.
|
||||
// Ref: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWatchedFiles
|
||||
.notification::<notif::DidChangeWatchedFiles>(Self::on_did_change_watched_files)
|
||||
.notification::<lsp_ext::ReloadFlake>(Self::on_reload_flake)
|
||||
//// Requests ////
|
||||
.request_snap::<req::GotoDefinition>(handler::goto_definition)
|
||||
.request_snap::<req::References>(handler::references)
|
||||
@ -382,6 +383,11 @@ impl Server {
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn on_reload_flake(&mut self, (): ()) -> NotifyResult {
|
||||
self.spawn_load_flake_workspace();
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
/// Spawn a task to (re)load the flake workspace via `flake.{nix,lock}`, including flake info,
|
||||
/// NixOS options and outputs (TODO).
|
||||
fn spawn_load_flake_workspace(&mut self) {
|
||||
|
@ -95,6 +95,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": []
|
||||
"commands": [
|
||||
{
|
||||
"command": "nil.reloadFlake",
|
||||
"title": "Reload the flake setup of the workspace",
|
||||
"category": "nil"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
3
editors/coc-nil/src/lsp_ext.ts
Normal file
3
editors/coc-nil/src/lsp_ext.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as lc from 'coc.nvim';
|
||||
|
||||
export const reloadFlake = new lc.NotificationType0('nil/reloadFlake');
|
@ -1,4 +1,5 @@
|
||||
import { ExtensionContext, services, LanguageClient, workspace } from 'coc.nvim';
|
||||
import { ExtensionContext, services, LanguageClient, workspace, commands } from 'coc.nvim';
|
||||
import * as lsp_ext from './lsp_ext';
|
||||
|
||||
const ROOT_SECTION = 'nil';
|
||||
|
||||
@ -16,4 +17,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
|
||||
};
|
||||
const client = new LanguageClient('nil', 'nil Language Server', serverOptions, clientOptions);
|
||||
context.subscriptions.push(services.registLanguageClient(client));
|
||||
context.subscriptions.push(commands.registerCommand('nil.reloadFlake', () => onReloadFlake(client)));
|
||||
}
|
||||
|
||||
function onReloadFlake(client: LanguageClient) {
|
||||
client.sendNotification(lsp_ext.reloadFlake);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user