Skip to content

Commit

Permalink
feat(lsp): accept option to disable code lens
Browse files Browse the repository at this point in the history
  • Loading branch information
kobyhallx committed Dec 15, 2023
1 parent 318b5d2 commit a2943b1
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions tooling/lsp/src/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::types::{CodeLensOptions, InitializeParams};
use async_lsp::ResponseError;
use lsp_types::{Position, TextDocumentSyncCapability, TextDocumentSyncKind};
use nargo_fmt::Config;
use serde::{Deserialize, Serialize};


use crate::{
types::{InitializeResult, NargoCapability, NargoTestsOptions, ServerCapabilities},
Expand Down Expand Up @@ -32,16 +34,47 @@ pub(crate) use {
test_run::on_test_run_request, tests::on_tests_request,
};

#[derive(Debug, Deserialize, Serialize)]
struct LspInitializationOptions {

#[serde(rename = "enableCodeLens", default = "default_enable_code_lens")]
enable_code_lens: bool,
}

fn default_enable_code_lens() -> bool {
true
}

impl Default for LspInitializationOptions {
fn default() -> Self {
Self {
enable_code_lens: default_enable_code_lens(),
}
}
}

pub(crate) fn on_initialize(
state: &mut LspState,
params: InitializeParams,
) -> impl Future<Output = Result<InitializeResult, ResponseError>> {

state.root_path = params.root_uri.and_then(|root_uri| root_uri.to_file_path().ok());

async {
let initialization_options = match params.initialization_options {
Some(initialization_options) => serde_json::from_value::<LspInitializationOptions>(initialization_options).unwrap_or_default(),
None => LspInitializationOptions::default(),
};

async move {
let text_document_sync = TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL);

let code_lens = CodeLensOptions { resolve_provider: Some(false) };

let code_lens = match initialization_options.enable_code_lens {
true => Some(CodeLensOptions { resolve_provider: Some(false) }),
false => None,
};

CodeLensOptions { resolve_provider: Some(false) };

let nargo = NargoCapability {
tests: Some(NargoTestsOptions {
Expand All @@ -54,7 +87,7 @@ pub(crate) fn on_initialize(
Ok(InitializeResult {
capabilities: ServerCapabilities {
text_document_sync: Some(text_document_sync),
code_lens_provider: Some(code_lens),
code_lens_provider: code_lens,
document_formatting_provider: true,
nargo: Some(nargo),
definition_provider: Some(lsp_types::OneOf::Left(true)),
Expand Down

0 comments on commit a2943b1

Please sign in to comment.