-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodIntellisense.bas
260 lines (215 loc) · 6.78 KB
/
modIntellisense.bas
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
Attribute VB_Name = "modIntellisense"
Public modules As New Collection
Public IncludeFiles() As String
Public FunctionPrototypes() As String
Function GetAutoCompleteStringForIncludes(partial As String) As String()
Dim x, matches() As String, i As Long
If AryIsEmpty(IncludeFiles) Then Exit Function
If Len(partial) = 0 Then Exit Function
For i = 0 To UBound(IncludeFiles)
x = LCase(IncludeFiles(i))
If Left(x, Len(partial)) = LCase(partial) Then
push matches, IncludeFiles(i)
End If
Next
GetAutoCompleteStringForIncludes = matches()
End Function
Function GetAutoCompleteString(partial As String) As String()
Dim x, matches() As String, i As Long
If AryIsEmpty(FunctionPrototypes) Then Exit Function
If Len(partial) = 0 Then Exit Function
For i = 0 To UBound(FunctionPrototypes)
x = LCase(FunctionPrototypes(i))
If Left(x, Len(partial)) = LCase(partial) Then
push matches, FunctionPrototypes(i)
End If
Next
GetAutoCompleteString = matches()
End Function
Function GetAutoCompleteStringForModule(methods As String, partial As String) As String()
Dim x, matches() As String, i As Long
Dim m() As String
If Len(methods) = 0 Then Exit Function
If Len(partial) = 0 Then Exit Function
m() = Split(methods, ":")
If AryIsEmpty(m) Then Exit Function
For i = 0 To UBound(m)
If Len(m(i)) > 0 Then
x = LCase(Trim(m(i)))
If Left(x, Len(partial)) = LCase(partial) Then
push matches, m(i)
End If
End If
Next
GetAutoCompleteStringForModule = matches()
End Function
Function LoadFunctionPrototypes(fpath As String)
Erase FunctionPrototypes
If Not FileExists(fpath) Then Exit Function
Dim tmp() As String, x
Const endMarker = "#modules"
tmp = Split(ReadFile(fpath), vbCrLf)
For Each x In tmp
x = Trim(x)
If Left(x, Len(endMarker)) = endMarker Then Exit For
If Len(x) > 0 And Left(x, 1) <> "#" And Left(x, 1) <> "'" Then
a = InStr(x, "(")
If a > 2 Then x = Mid(x, 1, a - 1)
push FunctionPrototypes, x
End If
Next
LoadFunctionPrototypes = UBound(FunctionPrototypes)
End Function
Function isIncludeFile(ByVal nameSpace As String) As Boolean
On Error Resume Next
nameSpace = Trim(nameSpace)
If Len(nameSpace) = 0 Then Exit Function
For i = 0 To UBound(IncludeFiles)
If LCase(nameSpace) = LCase(GetBaseName(IncludeFiles(i))) Then
isIncludeFile = True
Exit Function
End If
Next
End Function
'this is overly simplistic..it doesnt account for multiple spaces or tabs..
'should use regular expression really...
Function isFileIncluded(ByVal fName As String, ByVal script As String) As Boolean
On Error Resume Next
fName = Trim(fName)
If Len(fName) = 0 Then Exit Function
If InStr(1, script, "import " & fName, vbTextCompare) > 0 Then
isFileIncluded = True
Exit Function
End If
If InStr(1, script, "include " & fName, vbTextCompare) > 0 Then
isFileIncluded = True
Exit Function
End If
End Function
Function InitIntellisense(includeDir As String) As Boolean
On Error Resume Next
Set modules = New Collection
If Not FolderExists(includeDir) Then Exit Function
Dim curList As String
Dim inBlock As Boolean
Dim curModule As String
Dim f
IncludeFiles() = GetFolderFiles(includeDir, ".bas", False)
For Each fpath In IncludeFiles
tmp = ReadFile(includeDir & "\" & fpath)
tmp = Replace(tmp, Chr(&HD), Empty)
tmp = Split(tmp, vbLf)
For Each x In tmp
x = Replace(x, vbTab, " ")
While InStr(x, " ") > 0
x = Replace(x, " ", " ")
Wend
x = Trim(x)
If Len(x) = 0 Then GoTo skipLine
If Left(x, 1) = "#" Or Left(x, 1) = "'" Then GoTo skipLine 'its a comment ignore this line..
words = Split(x, " ")
If LCase(words(0)) = "module" Then curModule = LCase(words(1))
If Len(curModule) = 0 Then GoTo skipLine 'dont start recording till were in the module declare..
If LCase(words(0)) = "const" Then curList = curList & " :" & words(1)
If LCase(words(0)) = "declare" Then
words(2) = Replace(words(2), "::", Empty)
curList = curList & " :" & words(2) 'declare sub xxxxx
End If
If LCase(words(0)) = "end" And LCase(words(1)) = "module" Then Exit For
skipLine:
Next
If Len(curModule) > 0 And Len(curList) > 0 Then
'Debug.Print modules.Count & ") " & curModule & ":" & curList
modules.Add Trim(curList), Trim(curModule)
End If
curList = Empty
curModule = Empty
Next
InitIntellisense = (Err.Number = 0)
End Function
'old Format
'
'#comment
'module
'{
' name1 name2
'}
'
'Function InitIntellisense(fpath As String) As Boolean
'
' On Error Resume Next
'
' If Not FileExists(fpath) Then Exit Function
'
' Dim curList As String
' Dim inBlock As Boolean
' Dim curModule As String
'
' tmp = Split(ReadFile(fpath), vbCrLf)
' For Each x In tmp
' x = Replace(x, vbTab, " ")
' x = Replace(x, " ", " ")
' x = Trim(x)
' If Len(x) = 0 Then GoTo skipLine
' If Left(x, 1) = "#" Or Left(x, 1) = "'" Then GoTo skipLine 'its a comment ignore this line..
'
' If curModule = "" Then
' curModule = x
' GoTo skipLine
' End If
'
' If inBlock And x = "{" Then
' MsgBox "Error parsing " & fpath & " you can not nest {} blocks", vbInformation
' Exit Function
' End If
'
' If x = "{" Then
' inBlock = True
' GoTo skipLine
' End If
'
' If x = "}" Then
' inBlock = False
' If curModule = Empty Then
' MsgBox "CurModule has not been named? error parsing " & fpath, vbInformation
' Exit Function
' End If
' If curList <> Empty Then
' modules.Add Trim(curList), curModule
' End If
' curList = Empty
' curModule = Empty
' GoTo skipLine
' End If
'
' AddLine x, curList
'
'
'skipLine:
' Next
'
' InitIntellisense = (Err.Number = 0)
'
'End Function
'
'Private Function AddLine(x, ByRef curList As String) As Boolean
'
' On Error Resume Next
'
' tmp = Split(x, " ")
' For Each Y In tmp
' If Len(Y) > 0 Then
' curList = curList & " :" & Y
' End If
' Next
'
' AddLine = (Err.Number = 0)
'
'End Function
'
'
'
'
'
'
'