From 1b957756ce20ca9265df1282d22011227e1d9812 Mon Sep 17 00:00:00 2001 From: Goulven Clec'h Date: Sat, 14 Dec 2024 16:25:28 +0100 Subject: [PATCH] rust & vscode implementation --- crates/weblsp/src/css.rs | 9 ++++++++- crates/weblsp/src/server.rs | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/weblsp/src/css.rs b/crates/weblsp/src/css.rs index 53294d5..a8a4c05 100644 --- a/crates/weblsp/src/css.rs +++ b/crates/weblsp/src/css.rs @@ -1,7 +1,8 @@ use csslsrs::service::LanguageService; use lsp_server::{Connection, Message, Request, Response}; use lsp_types::request::{ - ColorPresentationRequest, DocumentColor, FoldingRangeRequest, HoverRequest, + ColorPresentationRequest, DocumentColor, DocumentSymbolRequest, FoldingRangeRequest, + HoverRequest, }; use std::error::Error; @@ -57,6 +58,12 @@ pub fn handle_request( ); send_result(connection, id, serde_json::to_value(&hover).unwrap())?; } + "textDocument/documentSymbol" => { + let (id, params) = cast::(req)?; + let symbols = language_service + .get_document_symbols(get_text_document(params.text_document, language_service)?); + send_result(connection, id, serde_json::to_value(&symbols).unwrap())?; + } _ => { eprintln!("handle_request: unsupported request: {}", req.method); } diff --git a/crates/weblsp/src/server.rs b/crates/weblsp/src/server.rs index 66c939b..617df84 100644 --- a/crates/weblsp/src/server.rs +++ b/crates/weblsp/src/server.rs @@ -4,6 +4,7 @@ pub(crate) fn get_server_capabilities() -> serde_json::Value { let capabilities = ServerCapabilities { hover_provider: Some(lsp_types::HoverProviderCapability::Simple(true)), color_provider: Some(lsp_types::ColorProviderCapability::Simple(true)), + document_symbol_provider: Some(lsp_types::OneOf::Left(true)), folding_range_provider: Some(lsp_types::FoldingRangeProviderCapability::Simple(true)), text_document_sync: Some(TextDocumentSyncCapability::Kind( lsp_types::TextDocumentSyncKind::FULL,