-
-
Notifications
You must be signed in to change notification settings - Fork 96
Feature - button-to-open-error-in-new-tab #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4f8ec44
6dcd965
fe57d2f
2709ad8
4a72732
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,18 @@ import { Diagnostic } from "vscode-languageserver-types"; | |
import { compressToEncodedURIComponent, d } from "../utils"; | ||
import { KNOWN_ERROR_NUMBERS } from "./consts/knownErrorNumbers"; | ||
import { miniLine } from "./miniLine"; | ||
import { Uri } from 'vscode'; | ||
import { PRETTY_TS_ERRORS_SCHEME } from '../provider/textDocumentProvider'; | ||
|
||
export const title = (diagnostic: Diagnostic) => d/*html*/ ` | ||
export const title = (diagnostic: Diagnostic, uri: Uri) => d/*html*/ ` | ||
<span style="color:#f96363;">⚠ Error </span>${ | ||
typeof diagnostic.code === "number" | ||
? d/*html*/ ` | ||
<span style="color:#5f5f5f;"> | ||
(TS${diagnostic.code}) | ||
${errorCodeExplanationLink(diagnostic.code)} | | ||
(TS${diagnostic.code}) | ||
${errorCodeExplanationLink(diagnostic.code)} | | ||
${errorMessageTranslationLink(diagnostic.message)} | ||
Comment on lines
+14
to
15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The links are not working in the preview panel, do you know why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call out, will look into it and report back |
||
${errorMessageInANewFile(diagnostic, uri)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why, but if a panel is opened and I click on another one, it stays on the previous one. |
||
</span> | ||
` | ||
: "" | ||
|
@@ -37,3 +40,15 @@ export const errorMessageTranslationLink = (message: Diagnostic["message"]) => { | |
</span> | ||
</a>`; | ||
}; | ||
|
||
export const errorMessageInANewFile = (diagnostic: Diagnostic, uri: Uri) => { | ||
const range = `${diagnostic.range.start.line}:${diagnostic.range.start.character}-${diagnostic.range.end.line}:${diagnostic.range.end.character}`; | ||
const virtualFileUri = Uri.parse(`${PRETTY_TS_ERRORS_SCHEME}:${encodeURIComponent(uri.fsPath + '.md')}?range=${encodeURIComponent(range)}`); | ||
const args = [virtualFileUri]; | ||
const href = Uri.parse(`command:markdown.showPreview?${encodeURIComponent(JSON.stringify(args))}`); | ||
return d/*html*/ ` | ||
<a title="Open in new tab" href="${href}"> | ||
<span class="codicon codicon-new-file"> | ||
</span> | ||
</a>`; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
span.hljs-title.class_ { | ||
color: #4ec9b0 | ||
} | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it'll look good for every theme. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Range, TextDocumentContentProvider } from 'vscode'; | ||
import { uriStore } from './uriStore'; | ||
|
||
export const PRETTY_TS_ERRORS_SCHEME = 'pretty-ts-errors'; | ||
|
||
export const textDocumentContentProvider: TextDocumentContentProvider = { | ||
provideTextDocumentContent(uri) { | ||
const searchParams = new URLSearchParams(uri.query); | ||
const fsPath = uri.fsPath.replace(/\.md$/, ''); | ||
if (!searchParams.has('range')) { | ||
return `range query parameter is missing for uri: ${uri}`; | ||
} | ||
const items = uriStore[fsPath]; | ||
if (!items) { | ||
return `no diagnostics found for ${fsPath}`; | ||
} | ||
const range = createRangeFromString(searchParams.get('range')!); | ||
const item = items.find((item) => { | ||
return item.range.isEqual(range); | ||
}); | ||
if (!item) { | ||
return `no diagnostic found for ${fsPath} with range ${JSON.stringify(range)}`; | ||
} | ||
const content = item.contents.map( | ||
(content) => content.value | ||
.replaceAll("```type\n", '```typescript\n')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to inject the |
||
.join('\n'); | ||
/* | ||
Explanation | ||
At this point the user has seen the tooltip and needs to see the markdown preview | ||
The preview needed ```type to be formatted correctly to the user but this is no longer needed. | ||
The markdown preview needs ```typescript to be formatted correctly. | ||
*/ | ||
return content; | ||
}, | ||
}; | ||
|
||
function createRangeFromString(range: string) { | ||
const [start, end] = range.split('-'); | ||
const [startLine, startCharacter] = start.split(':').map(Number); | ||
const [endLine, endCharacter] = end.split(':').map(Number); | ||
return new Range(startLine, startCharacter, endLine, endCharacter); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add
|
before the new icon?