Skip to content

Commit b8d9f07

Browse files
authoredApr 7, 2018
Merge pull request #17 from mads-hartmann/completions-based-on-your-PATH
Completions based on your path
2 parents 4db59d7 + 3dfff09 commit b8d9f07

19 files changed

+806
-344
lines changed
 

‎.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"search.exclude": {
77
"out": true
88
},
9+
"tslint.autoFixOnSave": true,
910
"typescript.tsdk": "./node_modules/typescript/lib",
1011
"typescript.tsc.autoDetect": "off"
1112
}

‎TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
https://github.com/Microsoft/vscode/wiki/Extension-Authoring:-Adopting-Multi-Root-Workspace-APIs
88
- [ ] Code completion
99
- [x] Based on symbols in the file
10+
- [x] Based on programs in your PATH
1011
- [ ] Based on all symbols in the workspace
11-
- [ ] Based on programs in your PATH
1212
- [ ] Code Outline
1313
- [x] Flat list of symbols
1414
- [ ] Implement proper hierarchy by providing parent names for nodes

‎server/bin/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
const server = require('../out/server')
3+
const server = require('../out/index')
44
const package = require('../package')
55

66
const args = process.argv

‎server/src/__tests__/__snapshots__/analyzer.test.ts.snap

+133
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,139 @@ Array [
107107
]
108108
`;
109109

110+
exports[`findSymbolCompletions return a list of symbols 1`] = `
111+
Array [
112+
Object {
113+
"data": Object {
114+
"name": "ret",
115+
"type": "function",
116+
},
117+
"kind": undefined,
118+
"label": "ret",
119+
},
120+
Object {
121+
"data": Object {
122+
"name": "configures",
123+
"type": "function",
124+
},
125+
"kind": undefined,
126+
"label": "configures",
127+
},
128+
Object {
129+
"data": Object {
130+
"name": "npm_config_loglevel",
131+
"type": "function",
132+
},
133+
"kind": undefined,
134+
"label": "npm_config_loglevel",
135+
},
136+
Object {
137+
"data": Object {
138+
"name": "node",
139+
"type": "function",
140+
},
141+
"kind": undefined,
142+
"label": "node",
143+
},
144+
Object {
145+
"data": Object {
146+
"name": "TMP",
147+
"type": "function",
148+
},
149+
"kind": undefined,
150+
"label": "TMP",
151+
},
152+
Object {
153+
"data": Object {
154+
"name": "BACK",
155+
"type": "function",
156+
},
157+
"kind": undefined,
158+
"label": "BACK",
159+
},
160+
Object {
161+
"data": Object {
162+
"name": "tar",
163+
"type": "function",
164+
},
165+
"kind": undefined,
166+
"label": "tar",
167+
},
168+
Object {
169+
"data": Object {
170+
"name": "MAKE",
171+
"type": "function",
172+
},
173+
"kind": undefined,
174+
"label": "MAKE",
175+
},
176+
Object {
177+
"data": Object {
178+
"name": "make",
179+
"type": "function",
180+
},
181+
"kind": undefined,
182+
"label": "make",
183+
},
184+
Object {
185+
"data": Object {
186+
"name": "clean",
187+
"type": "function",
188+
},
189+
"kind": undefined,
190+
"label": "clean",
191+
},
192+
Object {
193+
"data": Object {
194+
"name": "node_version",
195+
"type": "function",
196+
},
197+
"kind": undefined,
198+
"label": "node_version",
199+
},
200+
Object {
201+
"data": Object {
202+
"name": "t",
203+
"type": "function",
204+
},
205+
"kind": undefined,
206+
"label": "t",
207+
},
208+
Object {
209+
"data": Object {
210+
"name": "url",
211+
"type": "function",
212+
},
213+
"kind": undefined,
214+
"label": "url",
215+
},
216+
Object {
217+
"data": Object {
218+
"name": "ver",
219+
"type": "function",
220+
},
221+
"kind": undefined,
222+
"label": "ver",
223+
},
224+
Object {
225+
"data": Object {
226+
"name": "isnpm10",
227+
"type": "function",
228+
},
229+
"kind": undefined,
230+
"label": "isnpm10",
231+
},
232+
Object {
233+
"data": Object {
234+
"name": "NODE",
235+
"type": "function",
236+
},
237+
"kind": undefined,
238+
"label": "NODE",
239+
},
240+
]
241+
`;
242+
110243
exports[`findSymbols returns a list of SymbolInformation if uri is found 1`] = `
111244
Array [
112245
Object {

‎server/src/__tests__/analyzer.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import FIXTURES from '../../../testing/fixtures'
2-
import * as analyzer from '../analyser'
2+
import Analyzer from '../analyser'
3+
4+
const analyzer = new Analyzer()
35

46
const CURRENT_URI = 'dummy-uri.sh'
57
beforeEach(() => {
@@ -65,3 +67,9 @@ describe('wordAtPoint', () => {
6567
// expect(analyzer.wordAtPoint(CURRENT_URI, 24, 4)).toEqual('else')
6668
})
6769
})
70+
71+
describe('findSymbolCompletions', () => {
72+
it('return a list of symbols', () => {
73+
expect(analyzer.findSymbolCompletions(CURRENT_URI)).toMatchSnapshot()
74+
})
75+
})
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as path from 'path'
2+
import Executables from '../executables'
3+
4+
const executablesPromise = Executables.fromPath(
5+
path.resolve(__dirname, '..', '..', '..', 'testing', 'executables'),
6+
)
7+
8+
describe('list', () => {
9+
it('finds executables on the PATH', async () => {
10+
expect.assertions(1)
11+
const executables = await executablesPromise
12+
const result = executables.list().find(x => x === 'iam-executable')
13+
return expect(result).toBeTruthy()
14+
})
15+
16+
it.skip('only considers files that have the executable bit set', async () => {
17+
expect.assertions(1)
18+
const executables = await executablesPromise
19+
const result = executables.list().find(x => x === 'iam-not-executable')
20+
return expect(result).toBeFalsy()
21+
})
22+
23+
it('only considers executable directly on the PATH', async () => {
24+
expect.assertions(1)
25+
const executables = await executablesPromise
26+
const result = executables.list().find(x => x === 'iam-executable-in-sub-folder')
27+
return expect(result).toBeFalsy()
28+
})
29+
})
30+
31+
describe('documentation', () => {
32+
it('uses `man` so it disregards the PATH it has been initialized with', async () => {
33+
expect.assertions(1)
34+
const executables = await executablesPromise
35+
const result = await executables.documentation('ls')
36+
return expect(result).toBeTruthy()
37+
})
38+
})
39+
40+
describe('isExecutableOnPATH', () => {
41+
it('looks at the PATH it has been initialized with', async () => {
42+
expect.assertions(1)
43+
const executables = await executablesPromise
44+
const result = executables.isExecutableOnPATH('ls')
45+
return expect(result).toEqual(false)
46+
})
47+
})

0 commit comments

Comments
 (0)