Skip to content

Commit

Permalink
fix: use abs file path as error ID
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jun 5, 2021
1 parent 6bc50c1 commit 2150ddd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/vue2-ts/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="hello">
<h1>{{ msg12 }}</h1>
<h1>{{ msg123 }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br />
check out the
Expand Down
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ export function lspDiagnosticToViteError(
if (!diagnostics.diagnostics.length) return null

const d = diagnostics.diagnostics[0]
const absPath = uriToAbsPath(diagnostics.uri)
const range = d.range
let loc: ErrorPayload['err']['loc']
if (range) {
loc = {
file: uriToAbsPath(diagnostics.uri),
file: absPath,
line: range.start.line + 1,
column: range.start.character + 1,
}
}

const fileText = readFileSync(uriToAbsPath(diagnostics.uri), 'utf-8')
const fileText = readFileSync(absPath, 'utf-8')
const location = range2Location(d.range)
const columns = codeFrameColumns(fileText, location)

Expand All @@ -112,7 +113,7 @@ export function lspDiagnosticToViteError(
columns
),
stack: '',
id: d.source,
id: absPath,
plugin: 'vite-plugin-ts-checker',
loc,
}
Expand All @@ -122,7 +123,7 @@ export function lspDiagnosticToViteError(
return {
message: ts.flattenDiagnosticMessageText(d.message, formatHost.getNewLine()),
stack: '',
id: 'dummy source',
id: absPath,
plugin: 'vite-plugin-ts-checker',
loc,
}
Expand Down

0 comments on commit 2150ddd

Please sign in to comment.