Skip to content

Commit

Permalink
fix snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
xb-bx committed Jan 30, 2024
1 parent d93559a commit df59c13
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/server/completion.odin
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,14 @@ get_selector_completion :: proc(
selector,
&items,
)
case SymbolSliceValue:
list.isIncomplete = false
append_magic_dynamic_array_completion(
position_context,
selector,
&items,
)

case SymbolMapValue:
list.isIncomplete = false
append_magic_map_completion(position_context, selector, &items)
Expand Down Expand Up @@ -1732,7 +1740,7 @@ append_magic_map_completion :: proc(

additionalTextEdits := make([]TextEdit, 1, context.temp_allocator)
additionalTextEdits[0] = remove_edit

symbol_str := get_expression_string_from_position_context(position_context)
//for
{
item := CompletionItem {
Expand All @@ -1743,7 +1751,7 @@ append_magic_map_completion :: proc(
textEdit = TextEdit {
newText = fmt.tprintf(
"for ${{1:k}}, ${{2:v}} in %v {{\n\t$0 \n}}",
symbol.name,
symbol_str,
),
range = {start = range.end, end = range.end},
},
Expand All @@ -1754,7 +1762,17 @@ append_magic_map_completion :: proc(
append(items, item)
}
}

get_expression_string_from_position_context :: proc(position_context: ^DocumentPositionContext) -> string {
src := position_context.file.src
if position_context.call != nil {
return src[position_context.call.pos.offset:position_context.call.end.offset]
} else if position_context.field != nil {
return src[position_context.field.pos.offset:position_context.field.end.offset]
} else if position_context.selector != nil {
return src[position_context.selector.pos.offset:position_context.selector.end.offset]
}
return ""
}
append_magic_dynamic_array_completion :: proc(
position_context: ^DocumentPositionContext,
symbol: Symbol,
Expand All @@ -1779,9 +1797,11 @@ append_magic_dynamic_array_completion :: proc(
additionalTextEdits := make([]TextEdit, 1, context.temp_allocator)
additionalTextEdits[0] = remove_edit

symbol_str := get_expression_string_from_position_context(position_context)

//len
{
text := fmt.tprintf("len(%v)", symbol.name)
text := fmt.tprintf("len(%v)", symbol_str)

item := CompletionItem {
label = "len",
Expand All @@ -1807,7 +1827,7 @@ append_magic_dynamic_array_completion :: proc(
textEdit = TextEdit {
newText = fmt.tprintf(
"for i in %v {{\n\t$0 \n}}",
symbol.name,
symbol_str,
),
range = {start = range.end, end = range.end},
},
Expand Down

0 comments on commit df59c13

Please sign in to comment.