|
@@ -11,6 +11,7 @@ import {
|
|
|
} from '@codemirror/state'
|
|
} from '@codemirror/state'
|
|
|
import { Annotation } from '../../../../../types/annotation'
|
|
import { Annotation } from '../../../../../types/annotation'
|
|
|
import { debugConsole } from '@/utils/debugging'
|
|
import { debugConsole } from '@/utils/debugging'
|
|
|
|
|
+import { sendMB } from '@/infrastructure/event-tracking'
|
|
|
|
|
|
|
|
const compileLintSourceConf = new Compartment()
|
|
const compileLintSourceConf = new Compartment()
|
|
|
|
|
|
|
@@ -56,29 +57,36 @@ const compileLogLintSource = (): Extension =>
|
|
|
const items: Diagnostic[] = []
|
|
const items: Diagnostic[] = []
|
|
|
const cursor = view.state.field(compileDiagnosticsState).iter()
|
|
const cursor = view.state.field(compileDiagnosticsState).iter()
|
|
|
while (cursor.value !== null) {
|
|
while (cursor.value !== null) {
|
|
|
|
|
+ const { diagnostic } = cursor.value
|
|
|
items.push({
|
|
items.push({
|
|
|
- ...cursor.value.diagnostic,
|
|
|
|
|
|
|
+ ...diagnostic,
|
|
|
from: cursor.from,
|
|
from: cursor.from,
|
|
|
to: cursor.to,
|
|
to: cursor.to,
|
|
|
|
|
+ renderMessage: () => renderMessage(diagnostic),
|
|
|
})
|
|
})
|
|
|
cursor.next()
|
|
cursor.next()
|
|
|
}
|
|
}
|
|
|
return items
|
|
return items
|
|
|
}, lintSourceConfig)
|
|
}, lintSourceConfig)
|
|
|
|
|
|
|
|
-class DiagnosticRangeValue extends RangeValue {
|
|
|
|
|
- constructor(public diagnostic: Diagnostic) {
|
|
|
|
|
|
|
+interface CompileLogDiagnostic extends Diagnostic {
|
|
|
|
|
+ compile?: true
|
|
|
|
|
+ ruleId?: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class CompileLogDiagnosticRangeValue extends RangeValue {
|
|
|
|
|
+ constructor(public diagnostic: CompileLogDiagnostic) {
|
|
|
super()
|
|
super()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const setCompileDiagnosticsEffect = StateEffect.define<Diagnostic[]>()
|
|
|
|
|
|
|
+const setCompileDiagnosticsEffect = StateEffect.define<CompileLogDiagnostic[]>()
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* A state field for the compile log diagnostics
|
|
* A state field for the compile log diagnostics
|
|
|
*/
|
|
*/
|
|
|
export const compileDiagnosticsState = StateField.define<
|
|
export const compileDiagnosticsState = StateField.define<
|
|
|
- RangeSet<DiagnosticRangeValue>
|
|
|
|
|
|
|
+ RangeSet<CompileLogDiagnosticRangeValue>
|
|
|
>({
|
|
>({
|
|
|
create() {
|
|
create() {
|
|
|
return RangeSet.empty
|
|
return RangeSet.empty
|
|
@@ -88,7 +96,7 @@ export const compileDiagnosticsState = StateField.define<
|
|
|
if (effect.is(setCompileDiagnosticsEffect)) {
|
|
if (effect.is(setCompileDiagnosticsEffect)) {
|
|
|
return RangeSet.of(
|
|
return RangeSet.of(
|
|
|
effect.value.map(diagnostic =>
|
|
effect.value.map(diagnostic =>
|
|
|
- new DiagnosticRangeValue(diagnostic).range(
|
|
|
|
|
|
|
+ new CompileLogDiagnosticRangeValue(diagnostic).range(
|
|
|
diagnostic.from,
|
|
diagnostic.from,
|
|
|
diagnostic.to
|
|
diagnostic.to
|
|
|
)
|
|
)
|
|
@@ -138,7 +146,7 @@ export const showCompileLogDiagnostics = (show: boolean) => {
|
|
|
const convertAnnotationToDiagnostic = (
|
|
const convertAnnotationToDiagnostic = (
|
|
|
doc: Text,
|
|
doc: Text,
|
|
|
annotation: Annotation
|
|
annotation: Annotation
|
|
|
-): Diagnostic => {
|
|
|
|
|
|
|
+): CompileLogDiagnostic => {
|
|
|
if (annotation.row < 0) {
|
|
if (annotation.row < 0) {
|
|
|
throw new Error(`Invalid annotation row ${annotation.row}`)
|
|
throw new Error(`Invalid annotation row ${annotation.row}`)
|
|
|
}
|
|
}
|
|
@@ -150,6 +158,27 @@ const convertAnnotationToDiagnostic = (
|
|
|
to: line.to, // NOTE: highlight whole line as synctex doesn't output column number
|
|
to: line.to, // NOTE: highlight whole line as synctex doesn't output column number
|
|
|
severity: annotation.type,
|
|
severity: annotation.type,
|
|
|
message: annotation.text,
|
|
message: annotation.text,
|
|
|
- // source: annotation.source, // NOTE: the source is displayed in the tooltip
|
|
|
|
|
|
|
+ ruleId: annotation.ruleId,
|
|
|
|
|
+ compile: true,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+export const renderMessage = (
|
|
|
|
|
+ diagnostic: Pick<
|
|
|
|
|
+ CompileLogDiagnostic,
|
|
|
|
|
+ 'message' | 'severity' | 'ruleId' | 'compile'
|
|
|
|
|
+ >
|
|
|
|
|
+) => {
|
|
|
|
|
+ const { message, severity, ruleId, compile = false } = diagnostic
|
|
|
|
|
+
|
|
|
|
|
+ const div = document.createElement('div')
|
|
|
|
|
+ div.textContent = message
|
|
|
|
|
+
|
|
|
|
|
+ window.setTimeout(() => {
|
|
|
|
|
+ if (div.isConnected) {
|
|
|
|
|
+ sendMB('lint-gutter-marker-view', { severity, ruleId, compile })
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 500) // 500ms delay to indicate intention, rather than accidental hover
|
|
|
|
|
+
|
|
|
|
|
+ return div
|
|
|
|
|
+}
|