Skip to content

Commit b058be8

Browse files
feat: Implement goto definition (#39)
1 parent fb52ce5 commit b058be8

File tree

8 files changed

+439
-48
lines changed

8 files changed

+439
-48
lines changed

crates/roughly/src/cli.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,32 +474,31 @@ pub fn ast(path: &Path) -> Result<(), DebugError> {
474474

475475
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
476476
pub struct ExperimentalFeatures {
477+
pub goto_definition: bool,
477478
pub range_formatting: bool,
478479
pub unused: bool,
479480
}
480481

481482
impl ExperimentalFeatures {
482483
pub fn parse(flags: &[impl AsRef<str>]) -> Self {
483-
let mut unused = false;
484-
let mut range_formatting = false;
484+
let mut features = ExperimentalFeatures::default();
485485

486486
for flag in flags {
487487
match flag.as_ref() {
488488
"all" => {
489-
unused = true;
490-
range_formatting = true;
489+
features.unused = true;
490+
features.range_formatting = true;
491+
features.goto_definition = true;
491492
}
492-
"range_formatting" => range_formatting = true,
493-
"unused" => unused = true,
493+
"range_formatting" => features.range_formatting = true,
494+
"goto_definition" => features.goto_definition = true,
495+
"unused" => features.unused = true,
494496
unknown => {
495497
warn(&format!("unknown experimental feature: {unknown}"));
496498
}
497499
}
498500
}
499501

500-
Self {
501-
unused,
502-
range_formatting,
503-
}
502+
features
504503
}
505504
}

crates/roughly/src/completions.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use {
22
crate::{
33
index::SymbolsMap,
4-
lsp_types::{CompletionItem, CompletionItemKind, CompletionResponse, Position, SymbolKind},
5-
tree::{self, kind},
4+
lsp_types::{
5+
CompletionItem, CompletionItemKind, CompletionItemLabelDetails, CompletionResponse,
6+
Position, SymbolKind,
7+
},
8+
tree::{self, field, kind},
69
utils,
710
},
8-
async_lsp::lsp_types::CompletionItemLabelDetails,
911
ropey::Rope,
1012
tree_sitter::{Node, Point, Query, StreamingIterator},
1113
};
@@ -130,10 +132,7 @@ pub fn get(
130132

131133
let local_symbols: Vec<CompletionItem> =
132134
{
133-
let point = Point {
134-
row: position.line as usize,
135-
column: position.character as usize,
136-
};
135+
let point = Point::new(position.line as usize, position.character as usize);
137136
tree.root_node()
138137
.descendant_for_point_range(point, point)
139138
.map(|node| {
@@ -143,12 +142,12 @@ pub fn get(
143142
.flat_map(|node| {
144143
let mut items = Vec::new();
145144

146-
if let Some(parameters) = node.child_by_field_name("parameters") {
145+
if let Some(parameters) = node.child_by_field_id(field::PARAMETERS) {
147146
items.extend(
148147
parameters
149148
.children_by_field_name("parameter", &mut parameters.walk())
150149
.filter_map(|parameter| {
151-
parameter.child_by_field_name("name").map(|name| {
150+
parameter.child_by_field_id(field::NAME).map(|name| {
152151
rope.byte_slice(name.byte_range()).to_string()
153152
})
154153
})
@@ -165,7 +164,7 @@ pub fn get(
165164
);
166165
}
167166

168-
if let Some(body) = node.child_by_field_name("body") {
167+
if let Some(body) = node.child_by_field_id(field::BODY) {
169168
items.extend(locals_completion(body, rope).into_iter().filter(
170169
|item| utils::starts_with_lowercase(&item.label, &query),
171170
));

0 commit comments

Comments
 (0)