@@ -51,58 +51,128 @@ LSPCompletionItem *lsp_completion(LSPDocument *doc, LSPPosition position,
5151 GrowableArray completions ;
5252 growable_array_init (& completions , arena , 32 , sizeof (LSPCompletionItem ));
5353
54- // Add keyword snippets
5554 const struct {
5655 const char * label ;
5756 const char * snippet ;
5857 const char * detail ;
5958 } keywords [] = {
60- { "const fn" ,
61- " const ${1:name} -> fn (${2:params}) ${3:Type} {\\n\\ t$0\ \n}" ,
59+ // Function declarations
60+ { "const fn" , " const ${1:name} -> fn (${2:params}) ${3:Type} {\n\ t$0\n}" ,
6261 "Function declaration" },
6362 {"pub const fn" ,
64- "pub const ${1:name} -> fn (${2:params}) ${3:Type} {\\n\\ t$0\ \n}" ,
63+ "pub const ${1:name} -> fn (${2:params}) ${3:Type} {\n\ t$0\n}" ,
6564 "Public function" },
6665
66+ // Generic functions
67+ {"const fn<T>" ,
68+ "const ${1:name} = fn<${2:T}>(${3:params}) ${4:Type} {\n\t$0\n}" ,
69+ "Generic function" },
70+ {"pub const fn<T>" ,
71+ "pub const ${1:name} = fn<${2:T}>(${3:params}) ${4:Type} {\n\t$0\n}" ,
72+ "Public generic function" },
73+
74+ // Type declarations
6775 {"const struct" ,
68- "const ${1:Name} -> struct {\\n\\ t${2:field}: ${3:Type}$0,\ \n};" ,
76+ "const ${1:Name} -> struct {\n\ t${2:field}: ${3:Type}$0,\n};" ,
6977 "Struct definition" },
70- {"const enum" , "const ${1:Name} -> enum {\\n\\t${2:Variant}$0,\\n};" ,
78+ {"const struct<T>" ,
79+ "const ${1:Name} -> struct<${2:T}> {\n\t${3:field}: ${4:Type}$0,\n};" ,
80+ "Generic struct" },
81+ {"const enum" , "const ${1:Name} -> enum {\n\t${2:Variant}$0,\n};" ,
7182 "Enum definition" },
7283 {"const var" , "const ${1:name}: ${2:Type} = ${3:value};$0" ,
7384 "Top-level constant" },
7485
75- {"if" , "if ${1:condition} {\\n\\t$0\\n}" , "If statement" },
76- {"if else" , "if ${1:condition} {\\n\\t${2}\\n} else {\\n\\t$0\\n}" ,
86+ // Control flow - if/elif/else
87+ {"if" , "if (${1:condition}) {\n\t$0\n}" , "If statement" },
88+ {"if else" , "if (${1:condition}) {\n\t${2}\n} else {\n\t$0\n}" ,
7789 "If-else statement" },
90+ {"elif" , "elif (${1:condition}) {\n\t$0\n}" , "Elif clause" },
7891
79- {"loop" , "loop {\\n\\t$0\\n}" , "Infinite loop" },
92+ // Loop patterns
93+ {"loop" , "loop {\n\t$0\n}" , "Infinite loop" },
94+ {"loop while" , "loop (${1:condition}) {\n\t$0\n}" , "While-style loop" },
8095 {"loop for" ,
81- "loop [${1:i}: int = 0](${1:i} < ${2:10}) : (++${1:i}) {\\n\\ t$0\ \n}" ,
96+ "loop [${1:i}: int = 0](${1:i} < ${2:10}) : (++${1:i}) {\n\ t$0\n}" ,
8297 "For-style loop" },
98+ {"loop for multi" ,
99+ "loop [${1:i}: int = 0, ${2:j}: int = 0](${1:i} < ${3:10}) : (++${1:i}) "
100+ "{\n\t$0\n}" ,
101+ "Multi-variable for loop" },
83102
84- {"switch" , "switch (${1:value}) {\\n\\t${2:case} => ${3:result};$0\\n}" ,
103+ // Switch patterns
104+ {"switch" , "switch (${1:value}) {\n\t${2:case} -> ${3:result};$0\n}" ,
85105 "Switch statement" },
106+ {"switch default" ,
107+ "switch (${1:value}) {\n\t${2:case} -> ${3:result};\n\t_ -> "
108+ "${4:default};$0\n}" ,
109+ "Switch with default case" },
86110
111+ // Variable declaration
87112 {"let" , "let ${1:name}: ${2:Type} = ${3:value};$0" ,
88113 "Variable declaration" },
89114
90- {"defer" , "defer free(${1:ptr});$0" , "Defer statement" },
91- {"defer block" , "defer {\\n\\t${1:cleanup()};\\n\\t$0\\n}" ,
92- "Defer block" },
115+ // Defer patterns
116+ {"defer block" , "defer {\n\t${1:cleanup()};$0\n}" , "Defer block" },
93117
94- {"@module" , "@module \\\"${1:name}\\\"$0" , "Module declaration" },
95- {"@use" , "@use \\\"${1:module}\\\" as ${2:alias}$0" , "Import module" },
118+ // Module system
119+ {"@module" , "@module \"${1:name}\"$0" , "Module declaration" },
120+ {"@use" , "@use \"${1:module}\" as ${2:alias}$0" , "Import module" },
96121
122+ // Flow control
97123 {"return" , "return ${1:value};$0" , "Return statement" },
98124 {"break" , "break;$0" , "Break statement" },
99125 {"continue" , "continue;$0" , "Continue statement" },
100126
101- {"main" , "const main -> fn () int {\\n\\t$0\\n\\treturn 0;\\n};" ,
127+ // Common functions
128+ {"main" , "const main -> fn () int {\n\t$0\n\treturn 0;\n};" ,
102129 "Main function" },
103130 {"outputln" , "outputln(${1:message});$0" , "Output with newline" },
131+ {"output" , "output(${1:message});$0" , "Output without newline" },
132+
133+ // Built-in functions
134+ {"input" , "input<${1:Type}>(\"${2:prompt}\")$0" , "Read typed input" },
135+ {"system" , "system(\"${1:command}\");$0" , "Execute system command" },
136+
137+ // Type operations
104138 {"cast" , "cast<${1:Type}>(${2:value})$0" , "Type cast" },
105139 {"sizeof" , "sizeof<${1:Type}>$0" , "Size of type" },
140+
141+ // Memory operations
142+ {"alloc" , "cast<${1:*Type}>(alloc(${2:size} * sizeof<${3:Type}>))$0" ,
143+ "Allocate memory" },
144+ {"alloc defer" ,
145+ "let ${1:ptr}: ${2:*Type} = cast<${2:*Type}>(alloc(${3:size} * "
146+ "sizeof<${4:Type}>));\ndefer free(${1:ptr});$0" ,
147+ "Allocate with defer cleanup" },
148+
149+ // Struct patterns
150+ {"struct method" , "${1:name} -> fn (${2:params}) ${3:Type} {\n\t$0\n}" ,
151+ "Struct method" },
152+ {"struct pub" , "pub:\n\t${1:field}: ${2:Type},$0" ,
153+ "Public struct fields" },
154+ {"struct priv" , "priv:\n\t${1:field}: ${2:Type},$0" ,
155+ "Private struct fields" },
156+
157+ // Array patterns
158+ {"array" , "[${1:Type}; ${2:size}]$0" , "Array type" },
159+ {"array init" , "let ${1:arr}: [${2:Type}; ${3:size}] = [${4:values}];$0" ,
160+ "Array initialization" },
161+
162+ // Pointer patterns
163+ {"pointer" , "*${1:Type}$0" , "Pointer type" },
164+ {"address of" , "&${1:variable}$0" , "Address-of operator" },
165+ {"dereference" , "*${1:pointer}$0" , "Dereference pointer" },
166+
167+ // Function attributes
168+ {"#returns_ownership" ,
169+ "#returns_ownership\nconst ${1:name} -> fn (${2:params}) ${3:*Type} "
170+ "{\n\t$0\n}" ,
171+ "Function returns owned pointer" },
172+ {"#takes_ownership" ,
173+ "#takes_ownership\nconst ${1:name} -> fn (${2:ptr}: ${3:*Type}) void "
174+ "{\n\t$0\n}" ,
175+ "Function takes ownership" },
106176 };
107177
108178 for (size_t i = 0 ; i < sizeof (keywords ) / sizeof (keywords [0 ]); i ++ ) {
0 commit comments