Skip to content

Commit

Permalink
Enable hover for var @"foo-bar"
Browse files Browse the repository at this point in the history
  • Loading branch information
FnControlOption committed Jul 12, 2023
1 parent 3e07ad0 commit 697d28e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
17 changes: 3 additions & 14 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,9 @@ pub fn autofix(server: *Server, allocator: std.mem.Allocator, handle: *const Doc
}

pub fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []const u8 {
if (pos_index + 1 >= handle.text.len) return "";
var start_idx = pos_index;

while (start_idx > 0 and Analyser.isSymbolChar(handle.text[start_idx - 1])) {
start_idx -= 1;
}

var end_idx = pos_index;
while (end_idx < handle.text.len and Analyser.isSymbolChar(handle.text[end_idx])) {
end_idx += 1;
}

if (end_idx <= start_idx) return "";
return handle.text[start_idx..end_idx];
const token_index = offsets.sourceIndexToTokenIndex(handle.tree, pos_index);
if (handle.tree.tokens.items(.tag)[token_index] != .identifier) return "";
return handle.tree.tokenSlice(token_index);
}

pub fn getLabelGlobal(pos_index: usize, handle: *const DocumentStore.Handle) error{OutOfMemory}!?Analyser.DeclWithHandle {
Expand Down
4 changes: 2 additions & 2 deletions src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,9 @@ fn resolveContainer(
/// If the identifier is a `fn_name`, `fn_arg_index` is the index of the fn's param
fn getIdentifierTokenIndexAndFnArgIndex(
tree: Ast,
dot_index: usize,
dot_index: Ast.TokenIndex,
fn_arg_index_out: *usize,
) ?usize {
) ?Ast.TokenIndex {
// at least 3 tokens should be present, `x{.`
if (dot_index < 2) return null;
const token_tags = tree.tokens.items(.tag);
Expand Down
4 changes: 2 additions & 2 deletions src/offsets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn positionToIndex(text: []const u8, position: types.Position, encoding: Enc
return line_start_index + line_byte_length;
}

pub fn sourceIndexToTokenIndex(tree: Ast, source_index: usize) usize {
pub fn sourceIndexToTokenIndex(tree: Ast, source_index: usize) Ast.TokenIndex {
std.debug.assert(source_index < tree.source.len);

const tokens_start = tree.tokens.items(.start);
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn sourceIndexToTokenIndex(tree: Ast, source_index: usize) usize {
break;
}

return upper_index;
return @intCast(upper_index);
}

pub fn tokenToIndex(tree: Ast, token_index: Ast.TokenIndex) usize {
Expand Down

0 comments on commit 697d28e

Please sign in to comment.