Skip to content

Commit

Permalink
fix(vls): show initial error overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 2, 2021
1 parent 93a36e7 commit 20c95e9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config = {
globalSetup: './scripts/jestGlobalSetup.js',
globalTeardown: './scripts/jestGlobalTeardown.js',
setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'],
testTimeout: process.env.CI ? 60000 : 60000,
testTimeout: process.env.CI ? 100000 : 30000,
collectCoverage: false,
collectCoverageFrom: ['packages/*/src/**/*.ts', 'packages/*/lib/**/*.js'],
detectOpenHandles: true,
Expand Down
39 changes: 20 additions & 19 deletions packages/checker-vls/src/commands/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ async function prepareClientConnection(workspaceUri: URI, options: DiagnosticOpt
absFilePath: uriToAbsPath(diagnostics.uri),
fileText: overlayErr.fileText,
})

options.errorCallback?.(diagnostics, overlayErr)
}

Expand Down Expand Up @@ -207,25 +208,6 @@ async function getDiagnostics(

const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f))

// watched diagnostics report
if (options.watch) {
chokidar
.watch(workspaceUri.fsPath, {
ignored: (path: string) => path.includes('node_modules'),
ignoreInitial: true,
})
.on('all', (event, path) => {
if (!path.endsWith('.vue')) return
clientConnection.sendNotification(DidChangeTextDocumentNotification.type, {
textDocument: {
uri: URI.file(path).toString(),
version: Date.now(),
},
contentChanges: [{ text: fs.readFileSync(path, 'utf-8') }],
})
})
}

// initial diagnostics report
// watch mode will run this full diagnostic at starting
let initialErrCount = 0
Expand Down Expand Up @@ -273,6 +255,25 @@ async function getDiagnostics(
}
}

// watched diagnostics report
if (options.watch) {
chokidar
.watch(workspaceUri.fsPath, {
ignored: (path: string) => path.includes('node_modules'),
ignoreInitial: false,
})
.on('all', (event, path) => {
if (!path.endsWith('.vue')) return
clientConnection.sendNotification(DidChangeTextDocumentNotification.type, {
textDocument: {
uri: URI.file(path).toString(),
version: Date.now(),
},
contentChanges: [{ text: fs.readFileSync(path, 'utf-8') }],
})
})
}

logUpdate(logChunk)
return initialErrCount
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function killServer() {
}

export async function pollingUntil<T>(poll: () => Promise<T>, until: (actual: T) => boolean) {
const maxTries = process.env.CI ? 500 : 100 // 25s / 5s
const maxTries = process.env.CI ? 1000 : 100 // 50s / 5s
for (let tries = 0; tries < maxTries; tries++) {
const actual = await poll()
if (until(actual)) {
Expand Down
32 changes: 18 additions & 14 deletions playground/vue2-vls/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ afterAll(async () => {
await sleep(WORKER_CLEAN_TIMEOUT)
})

// TODO: why does it broken in Windows 😫
const isWindows = os.platform() === 'win32'

describe('vue2-vls', () => {
beforeAll(async () => {
await viteServe({ cwd: testDir, port: 8080, path: '/vue-template/' })
Expand All @@ -35,24 +38,25 @@ describe('vue2-vls', () => {

describe('serve', () => {
it('get initial error and subsequent error', async () => {
// const [message1, file1] = await getHmrOverlayText()
// TODO: vls checker missed initial error overlay 😅
// expect(message1).toContain('> 3 | <h1>{{ msg1 }}</h1>')
// expect(message1).toContain(
// `Property 'msg1' does not exist on type 'CombinedVueInstance<{ msg: string; } & Vue, object, object, object, Record<never, any>>'. Did you mean 'msg'?`
// )
// expect(file1).toContain('vue2-vls/src/components/HelloWorld.vue:3:12')

editFile('src/components/HelloWorld.vue', (code) => code.replace('msg1', 'msg2'))

if (os.platform() === 'win32') {
if (isWindows) {
expect(1).toBe(1)
return // TODO: why does it broken in Windows 😫
} else {
const [message1, file1] = await getHmrOverlayText()
expect(message1).toContain('> 3 | <h1>{{ msg1 }}</h1>')
expect(message1).toContain(
`Property 'msg1' does not exist on type 'CombinedVueInstance<{ msg: string; } & Vue, object, object, object, Record<never, any>>'. Did you mean 'msg'?`
)
expect(file1).toContain('vue2-vls/src/components/HelloWorld.vue:3:12')
}

editFile('src/components/HelloWorld.vue', (code) => code.replace('msg1', 'msg2'))
await sleep(process.env.CI ? 5000 : 2000)
const [message2] = await getHmrOverlayText()
expect(message2).toContain(`> 3 | <h1>{{ msg2 }}</h1>`)
if (isWindows) {
expect(1).toBe(1)
} else {
const [message2] = await getHmrOverlayText()
expect(message2).toContain(`> 3 | <h1>{{ msg2 }}</h1>`)
}
})
})

Expand Down

0 comments on commit 20c95e9

Please sign in to comment.