浏览代码

const value in hover tip and comletion items

Geequlim 8 年之前
父节点
当前提交
e9cd9f37d4
共有 3 个文件被更改,包括 17 次插入6 次删除
  1. 3 2
      src/config.ts
  2. 3 1
      src/gdscript/hoverprovider.ts
  3. 11 3
      src/gdscript/symbolparser.ts

+ 3 - 2
src/config.ts

@@ -147,13 +147,14 @@ class Config {
           const _items: CompletionItem[] = [];
           const _items: CompletionItem[] = [];
           for (let name of Object.keys(items)) {
           for (let name of Object.keys(items)) {
             const signature = (script.signatures && script.signatures[name])?script.signatures[name]:"";
             const signature = (script.signatures && script.signatures[name])?script.signatures[name]:"";
+            const cvalue = (script.constvalues && script.constvalues[name])?script.constvalues[name]:""; 
             const item = new CompletionItem(name+signature, kind);
             const item = new CompletionItem(name+signature, kind);
             item.sortText = name;
             item.sortText = name;
             item.filterText = name;
             item.filterText = name;
-            item.detail = workspace.asRelativePath(path);
+            item.detail = cvalue;
             item.insertText = insertText(name) + (signature=="()"?"()":"");
             item.insertText = insertText(name) + (signature=="()"?"()":"");
             item.documentation = (script.documents && script.documents[name])?script.documents[name]+"\r\n":"";
             item.documentation = (script.documents && script.documents[name])?script.documents[name]+"\r\n":"";
-            item.documentation += `${kindName} defined in ${item.detail}`;
+            item.documentation += `${kindName} defined in ${workspace.asRelativePath(path)}`;
             _items.push(item);
             _items.push(item);
           }
           }
           return _items;
           return _items;

+ 3 - 1
src/gdscript/hoverprovider.ts

@@ -48,10 +48,12 @@ class GDScriptHoverProvider implements HoverProvider {
                             let signature = "";
                             let signature = "";
                             if(type == "func"|| type == "signal" && script.signatures[name])
                             if(type == "func"|| type == "signal" && script.signatures[name])
                                 signature = script.signatures[name];
                                 signature = script.signatures[name];
+                            if(type == "const" && script.constvalues[name])
+                                signature = ` = ${script.constvalues[name]}`;
                             _items.push({language:'gdscript', value:`${type} ${name}${signature}`});
                             _items.push({language:'gdscript', value:`${type} ${name}${signature}`});
                             let doc = script.documents[name];
                             let doc = script.documents[name];
                             doc = doc?doc+"\r\n\r\n":"";
                             doc = doc?doc+"\r\n\r\n":"";
-                            doc += `*Defined in [${dfile}](${Uri.file(path).toString()}).*`
+                            doc += `*Defined in [${dfile}](${Uri.file(path).toString()})*`
                             _items.push(doc)
                             _items.push(doc)
                             break;
                             break;
                         }
                         }

+ 11 - 3
src/gdscript/symbolparser.ts

@@ -11,7 +11,9 @@ interface GDScript {
   native: string,
   native: string,
   signatures: {},
   signatures: {},
   // symbol: marked string
   // symbol: marked string
-  documents: {}
+  documents: {},
+  // name : value
+  constvalues: {}
 }
 }
 
 
 class GDScriptSymbolParser {
 class GDScriptSymbolParser {
@@ -28,7 +30,8 @@ class GDScriptSymbolParser {
         base: "Object",
         base: "Object",
         native: "Object",
         native: "Object",
         signatures: {},
         signatures: {},
-        documents: {}
+        documents: {},
+        constvalues: {}
     }
     }
     const text  = content;
     const text  = content;
     const lines = text.split(/\r?\n/);
     const lines = text.split(/\r?\n/);
@@ -86,7 +89,7 @@ class GDScriptSymbolParser {
       while( line > 0){
       while( line > 0){
         const linecontent = lines[line];
         const linecontent = lines[line];
         let match = linecontent.match(/\s*#\s*(.*)/);
         let match = linecontent.match(/\s*#\s*(.*)/);
-        const commentAtEnd = linecontent.match(/[A-z0-8,\[\{]+\s*#\s*(.*)/);
+        const commentAtEnd = linecontent.match(/[\w'",\[\{\]\}\(\)]+\s*#\s*(.*)/);
         if(!match && line != range.start.line)
         if(!match && line != range.start.line)
           break;
           break;
         if(commentAtEnd && line != range.start.line)
         if(commentAtEnd && line != range.start.line)
@@ -138,6 +141,11 @@ class GDScriptSymbolParser {
       if(newdoc == "" && script.documents[key])
       if(newdoc == "" && script.documents[key])
         newdoc = script.documents[key];
         newdoc = script.documents[key];
       script.documents[key] = newdoc;
       script.documents[key] = newdoc;
+      
+      const linecontent = lines[r.start.line];
+      const match = linecontent.match(/const\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*=\s*([\w+]+\(.*\)|"[^"]*"|\-?\d+\.?\d*|\[.*\]|\{.*\})/);
+      if(match && match.length && match.length >1)
+        script.constvalues[key] = match[2];
     }
     }
     
     
     let classnames = getMatches(text, /class\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*extends\s+/g, 1);
     let classnames = getMatches(text, /class\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*extends\s+/g, 1);