-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathsuggestlib.nim
128 lines (115 loc) · 4.27 KB
/
suggestlib.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import macros, os
const explicitSourcePath {.strdefine.} = getCurrentCompilerExe().parentDir.parentDir
macro mImport(path: static[string]): untyped =
result = newNimNode(nnkStmtList)
result.add(quote do:
import `path`
)
mImport(explicitSourcePath / "nimsuggest" / "nimsuggest.nim")
import messageenums
import strutils
import compiler / ast
export Suggest
export IdeCmd
export NimSuggest
export initNimSuggest
proc stopNimSuggest*(nimsuggest: NimSuggest): int = 42
proc `$`*(suggestion: Suggest): string =
let sep = ", "
result = "(section: " & $suggestion.section
result.add sep
result.add "symKind: " & $suggestion.symkind.TSymKind
result.add sep
result.add "qualifiedPath: " & suggestion.qualifiedPath.join(".")
result.add sep
result.add "forth: " & suggestion.forth
result.add sep
result.add "filePath: " & suggestion.filePath
result.add sep
result.add "line: " & $suggestion.line
result.add sep
result.add "column: " & $suggestion.column
result.add sep
result.add "doc: " & $suggestion.doc
result.add sep
result.add "quality: " & $suggestion.quality
result.add sep
result.add "line: " & $suggestion.line
result.add sep
result.add "prefix: " & $suggestion.prefix
result.add ")"
func nimSymToLSPKind*(suggest: Suggest): CompletionItemKind =
case $suggest.symKind.TSymKind:
of "skConst": CompletionItemKind.Value
of "skEnumField": CompletionItemKind.Enum
of "skForVar": CompletionItemKind.Variable
of "skIterator": CompletionItemKind.Keyword
of "skLabel": CompletionItemKind.Keyword
of "skLet": CompletionItemKind.Value
of "skMacro": CompletionItemKind.Snippet
of "skMethod": CompletionItemKind.Method
of "skParam": CompletionItemKind.Variable
of "skProc": CompletionItemKind.Function
of "skResult": CompletionItemKind.Value
of "skTemplate": CompletionItemKind.Snippet
of "skType": CompletionItemKind.Class
of "skVar": CompletionItemKind.Field
of "skFunc": CompletionItemKind.Function
else: CompletionItemKind.Property
func nimSymToLSPKind*(suggest: byte): SymbolKind =
case $TSymKind(suggest):
of "skConst": SymbolKind.Constant
of "skEnumField": SymbolKind.EnumMember
of "skIterator": SymbolKind.Function
of "skConverter": SymbolKind.Function
of "skLet": SymbolKind.Variable
of "skMacro": SymbolKind.Function
of "skMethod": SymbolKind.Method
of "skProc": SymbolKind.Function
of "skTemplate": SymbolKind.Function
of "skType": SymbolKind.Class
of "skVar": SymbolKind.Variable
of "skFunc": SymbolKind.Function
else: SymbolKind.Function
func nimSymDetails*(suggest: Suggest): string =
case $suggest.symKind.TSymKind:
of "skConst": "const " & suggest.qualifiedPath.join(".") & ": " & suggest.forth
of "skEnumField": "enum " & suggest.forth
of "skForVar": "for var of " & suggest.forth
of "skIterator": suggest.forth
of "skLabel": "label"
of "skLet": "let of " & suggest.forth
of "skMacro": "macro"
of "skMethod": suggest.forth
of "skParam": "param"
of "skProc": suggest.forth
of "skResult": "result"
of "skTemplate": suggest.forth
of "skType": "type " & suggest.qualifiedPath.join(".")
of "skVar": "var of " & suggest.forth
else: suggest.forth
func nimDocstring*(suggest: Suggest): string =
suggest.doc
template createFullCommand(command: untyped) {.dirty.} =
proc command*(nimsuggest: NimSuggest, file: string, dirtyfile = "",
line: int, col: int): seq[Suggest] =
nimsuggest.runCmd(`ide command`, AbsoluteFile file, AbsoluteFile dirtyfile, line, col)
template createFileOnlyCommand(command: untyped) {.dirty.} =
proc command*(nimsuggest: NimSuggest, file: string, dirtyfile = ""): seq[Suggest] =
nimsuggest.runCmd(`ide command`, AbsoluteFile file, AbsoluteFile dirtyfile, 0, 0)
createFullCommand(sug)
createFullCommand(con)
createFullCommand(def)
createFullCommand(use)
createFullCommand(dus)
createFileOnlyCommand(chk)
#createFileOnlyCommand(`mod`)
createFileOnlyCommand(highlight)
createFileOnlyCommand(outline)
createFileOnlyCommand(known)
when isMainModule:
var graph = initNimSuggest("/home/peter/div/nimlsp/suglibtest.nim", nimPath = "/home/peter/div/Nim")
var suggestions = graph.sug("/home/peter/div/nimlsp/suglibtest.nim", "/home/peter/div/nimlsp/suglibtest.nim", 7, 2)
echo "Got ", suggestions.len, " suggestions"
for suggestion in suggestions:
echo suggestion