aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2021-03-17 02:06:17 +0100
committerDanielGavin <danielgavin5@hotmail.com>2021-03-17 02:06:17 +0100
commita8abe7726ac2b717f0b7e2e1b31c8ec0566d9374 (patch)
treec54e8db2a158dc01ec0d4c6e0cb75e8ae7979aa2 /src
parent8b2eef8af0a50f22b06af603fc6e4f09b218f25c (diff)
more bitset completion with assignments
Diffstat (limited to 'src')
-rw-r--r--src/server/analysis.odin29
-rw-r--r--src/server/completion.odin34
2 files changed, 60 insertions, 3 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 8c3f93f..2e95c3a 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -826,7 +826,6 @@ resolve_type_identifier :: proc (ast_context: ^AstContext, node: ast.Ident) -> (
expr = ident
},
};
-
return symbol, true;
} else {
@@ -1015,7 +1014,7 @@ resolve_first_symbol_from_binary_expression :: proc (ast_context: ^AstContext, b
//Fairly simple function to find the earliest identifier symbol in binary expression.
- if binary.left != nil && binary.left.derived != nil {
+ if binary.left != nil {
if ident, ok := binary.left.derived.(ast.Ident); ok {
if s, ok := resolve_type_identifier(ast_context, ident); ok {
@@ -1031,7 +1030,7 @@ resolve_first_symbol_from_binary_expression :: proc (ast_context: ^AstContext, b
}
- if binary.right != nil && binary.right.derived != nil {
+ if binary.right != nil {
if ident, ok := binary.right.derived.(ast.Ident); ok {
if s, ok := resolve_type_identifier(ast_context, ident); ok {
return s, ok;
@@ -2038,6 +2037,26 @@ get_document_position_context :: proc (document: ^Document, position: common.Pos
get_document_position(decl, &position_context);
}
+ if !position_in_node(position_context.comp_lit, position_context.position) {
+ position_context.comp_lit = nil;
+ }
+
+ if !position_in_node(position_context.parent_comp_lit, position_context.position) {
+ position_context.parent_comp_lit = nil;
+ }
+
+ if !position_in_node(position_context.assign, position_context.position) {
+ position_context.assign = nil;
+ }
+
+ if !position_in_node(position_context.binary, position_context.position) {
+ position_context.binary = nil;
+ }
+
+ if !position_in_node(position_context.parent_binary, position_context.position) {
+ position_context.parent_binary = nil;
+ }
+
if hint == .Completion && position_context.selector == nil && position_context.field == nil {
fallback_position_context_completion(document, position, &position_context);
} else if hint == .SignatureHelp && position_context.call == nil {
@@ -2114,6 +2133,8 @@ fallback_position_context_completion :: proc (document: ^Document, position: com
i -= 1;
}
+ //log.error(u8(position_context.file.src[end]));
+
if i >= 0 && position_context.file.src[end] == '.' {
empty_dot = true;
end -= 1;
@@ -2141,6 +2162,8 @@ fallback_position_context_completion :: proc (document: ^Document, position: com
tokenizer.init(&p.tok, str, position_context.file.fullpath, parser_warning_handler);
+ //log.error(string(position_context.file.src[begin_offset:end_offset]));
+
p.tok.ch = ' ';
p.tok.line_count = position.line;
p.tok.offset = begin_offset;
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 34fc9bf..40f633c 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -439,6 +439,27 @@ get_implicit_completion :: proc (ast_context: ^AstContext, position_context: ^Do
}
}
}
+ } else if position_context.comp_lit != nil && position_context.assign != nil && position_context.assign.lhs != nil && len(position_context.assign.lhs) == 1 && is_bitset_assignment_operator(position_context.assign.op.text) {
+
+ if symbol, ok := resolve_type_expression(ast_context, position_context.assign.lhs[0]); ok {
+
+ if value, ok := unwrap_bitset(ast_context, symbol); ok {
+
+ for name in value.names {
+
+ item := CompletionItem {
+ label = name,
+ kind = .EnumMember,
+ detail = name,
+ };
+
+ append(&items, item);
+ }
+ }
+
+ }
+
+
} else if position_context.comp_lit != nil {
if position_context.parent_comp_lit.type == nil {
@@ -810,6 +831,19 @@ bitset_operators: map[string]bool = {
">" = true,
};
+bitset_assignment_operators: map[string]bool = {
+ "|=" = true,
+ "&=" = true,
+ "~=" = true,
+ "<=" = true,
+ ">=" = true,
+ "=" = true,
+};
+
is_bitset_binary_operator :: proc (op: string) -> bool {
return op in bitset_operators;
}
+
+is_bitset_assignment_operator :: proc (op: string) -> bool {
+ return op in bitset_assignment_operators;
+} \ No newline at end of file