Beaglefoot / awk-language-server

Language Server for AWK and associated VSCode client extension
https://marketplace.visualstudio.com/items?itemName=beaglefoot.awk-ide-vscode
MIT License
90 stars 5 forks source link

snip not work #44

Closed Shane-XB-Qian closed 1 year ago

Shane-XB-Qian commented 1 year ago

1, seems somewhere did not set for snip compl item:

item: {'label': 'for', 'data': {'type': 2}, 'kind': 15}

e.g: no insertTextFormat is 2 found.

  1. perhaps should be using 'prefix' as its label, or following patch should be required.
diff --git a/server/snippets.json b/server/snippets.json
index f7ea08b..aa3bdab 100644
--- a/server/snippets.json
+++ b/server/snippets.json
@@ -39,13 +39,13 @@
         "description": "! operator",
         "prefix": "not",
         "body": [
             "!${1:expression}"
         ]
     },
-    "compare to": {
+    "compare-to": {
         "description": "comparison operator",
         "prefix": "compare-to",
         "body": [
             "${1:expression} ${2|<,>,<=,>=,==,!=|} ${3:expression}"
         ]
     },
@@ -68,13 +68,13 @@
         "prefix": "if",
         "body": [
             "if (${1:condition})",
             "\t$0"
         ]
     },
-    "if else": {
+    "if-else": {
         "description": "if else operator",
         "prefix": "if-else",
         "body": [
             "if (${1:condition})",
             "\t${2:print}",
             "else",
@@ -87,13 +87,13 @@
         "prefix": "while",
         "body": [
             "while (${1:condition})",
             "\t$0"
         ]
     },
-    "do while": {
+    "do-while": {
         "description": "do while operator",
         "prefix": "do-while",
         "body": [
             "do",
             "\t$0",
             "while (${1:condition})"
Beaglefoot commented 1 year ago

Are you sure your editor supports snippets as part of LSP?

Shane-XB-Qian commented 1 year ago

yes. bashls had done the same.

-- shane.xb.qian

EmilyGraceSeville7cf commented 1 year ago

What editor version do u use? Maybe I can try to reproduce the bug (or maybe it's a feature 😄). Maybe there is already such issue filled for this editor? 🤔

Shane-XB-Qian commented 1 year ago

yea, i tried to debug with following, but seems difficult to make it be right though i got the snip items if so.

diff --git a/server/src/completion.ts b/server/src/completion.ts
index 1c53179..eabfd22 100644
--- a/server/src/completion.ts
+++ b/server/src/completion.ts
@@ -73,15 +73,19 @@ export function initCompletionList(docs: Documentation, snippets: Snippets): voi
       data: { type: DataEntryType.Documentation, jsonPath: `patterns.${key}` },
     })),
   )

   predefinedCompletionListLight.push(
     ...Object.entries(snippets).map(([title, info]) => ({
-      label: title,
+      label: info.prefix,
       kind: CompletionItemKind.Snippet,
       data: { type: DataEntryType.Snippet },
+
+      detail: info.description,
+      insertText: info.body.join('\n'),
+      insertTextFormat: InsertTextFormat.Snippet,
     })),
   )
 }

 export function getPredefinedCompletionItems(): AWKCompletionItem[] {
   return predefinedCompletionListLight