aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r--crates/server/src/main_loop/handlers.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index f51909280..e9dc78420 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
3use languageserver_types::{ 3use languageserver_types::{
4 Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, 4 Diagnostic, DiagnosticSeverity, Url, DocumentSymbol,
5 Command, TextDocumentIdentifier, WorkspaceEdit, 5 Command, TextDocumentIdentifier, WorkspaceEdit,
6 SymbolInformation, Location, 6 SymbolInformation,
7}; 7};
8use libanalysis::{World, Query}; 8use libanalysis::{World, Query};
9use libeditor; 9use libeditor;
@@ -13,7 +13,7 @@ use serde_json::{to_value, from_value};
13use ::{ 13use ::{
14 req::{self, Decoration}, Result, 14 req::{self, Decoration}, Result,
15 util::FilePath, 15 util::FilePath,
16 conv::{Conv, ConvWith, MapConvWith}, 16 conv::{Conv, ConvWith, TryConvWith, MapConvWith},
17}; 17};
18 18
19pub fn handle_syntax_tree( 19pub fn handle_syntax_tree(
@@ -115,15 +115,10 @@ pub fn handle_workspace_symbol(
115 115
116 for (path, symbol) in world.world_symbols(query).take(128) { 116 for (path, symbol) in world.world_symbols(query).take(128) {
117 let line_index = world.file_line_index(path)?; 117 let line_index = world.file_line_index(path)?;
118
119 let info = SymbolInformation { 118 let info = SymbolInformation {
120 name: symbol.name.to_string(), 119 name: symbol.name.to_string(),
121 kind: symbol.kind.conv(), 120 kind: symbol.kind.conv(),
122 location: Location::new( 121 location: (path, symbol.node_range).try_conv_with(&line_index)?,
123 Url::from_file_path(path)
124 .map_err(|()| format_err!("invalid url"))?,
125 symbol.node_range.conv_with(&line_index),
126 ),
127 container_name: None, 122 container_name: None,
128 }; 123 };
129 acc.push(info); 124 acc.push(info);
@@ -132,6 +127,22 @@ pub fn handle_workspace_symbol(
132 Ok(Some(acc)) 127 Ok(Some(acc))
133} 128}
134 129
130pub fn handle_goto_definition(
131 world: World,
132 params: req::TextDocumentPositionParams,
133) -> Result<Option<req::GotoDefinitionResponse>> {
134 let path = params.text_document.file_path()?;
135 let line_index = world.file_line_index(&path)?;
136 let offset = params.position.conv_with(&line_index);
137 let mut res = Vec::new();
138 for (path, symbol) in world.approximately_resolve_symbol(&path, offset)? {
139 let line_index = world.file_line_index(path)?;
140 let location = (path, symbol.node_range).try_conv_with(&line_index)?;
141 res.push(location)
142 }
143 Ok(Some(req::GotoDefinitionResponse::Array(res)))
144}
145
135pub fn handle_execute_command( 146pub fn handle_execute_command(
136 world: World, 147 world: World,
137 mut params: req::ExecuteCommandParams, 148 mut params: req::ExecuteCommandParams,