Skip to content

Commit 76ad516

Browse files
committed
dummy service: support usage without lib
1 parent 01e8eaf commit 76ad516

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

typescript/src/dummyLanguageService.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
// only for basic testing, as vscode is actually using server
22
import ts from 'typescript/lib/tsserverlibrary'
3+
import path from 'path'
34

4-
export const createLanguageService = (files: Record<string, string>) => {
5+
export const createLanguageService = (files: Record<string, string>, { useLib = true }: { useLib?: boolean } = {}) => {
56
let dummyVersion = 1
7+
let defaultLibDir: string | undefined
68
const languageService = ts.createLanguageService({
79
getProjectVersion: () => dummyVersion.toString(),
810
getScriptVersion: () => dummyVersion.toString(),
911
getCompilationSettings: () => ({ allowJs: true, jsx: ts.JsxEmit.Preserve, target: ts.ScriptTarget.ESNext }),
1012
getScriptFileNames: () => Object.keys(files),
1113
getScriptSnapshot: fileName => {
12-
const contents = files[fileName]
14+
let contents = files[fileName]
15+
if (useLib && path.dirname(fileName) === defaultLibDir) contents = ts.sys.readFile(fileName)
1316
if (contents === undefined) return
1417
return ts.ScriptSnapshot.fromString(contents)
1518
},
1619
getCurrentDirectory: () => '',
17-
getDefaultLibFileName: () => require.resolve('typescript/lib/lib.esnext.full.d.ts'),
20+
getDefaultLibFileName: options => {
21+
const defaultLibPath = ts.getDefaultLibFilePath(options)
22+
defaultLibDir = path.dirname(defaultLibPath)
23+
return defaultLibPath
24+
},
1825
fileExists(path) {
1926
return path in files
2027
},

typescript/test/completions.spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@ test('Not banned positions for our method snippets', () => {
101101
}
102102
})
103103

104-
test.skip('Remove Useless Function Props', () => {
105-
const [pos] = newFileContents(/* ts */ `
104+
test('Function props: cleans & highlights', () => {
105+
const [pos, pos2] = newFileContents(/* ts */ `
106106
function fn() {}
107107
fn./*|*/
108+
let a: {
109+
(): void
110+
sync: 5
111+
}
112+
a./*|*/
108113
`)
109-
console.log(getCompletionsAtPosition(pos!)?.entries)
110-
// expect(entryNames).not.includes('bind')
114+
const entryNames = getCompletionsAtPosition(pos!)?.entryNames
115+
expect(entryNames).not.includes('Symbol')
116+
const entryNamesHighlighted = getCompletionsAtPosition(pos2!)?.entryNames
117+
expect(entryNamesHighlighted).includes('☆sync')
111118
})

0 commit comments

Comments
 (0)