From 0f1b94f8b92365caa510897eef2190e0b1e37eef Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 29 Jul 2024 08:41:02 -0700 Subject: [PATCH] remove suss linter ext we dont use (#3150) remove suss linter ext we dont use Signed-off-by: Jess Frazelle --- e2e/playwright/flow-tests.spec.ts | 6 +-- .../codemirror-lsp-client/src/plugin/lint.ts | 12 ------ .../codemirror-lsp-client/src/plugin/lsp.ts | 16 ------- src/components/ModelingMachineProvider.tsx | 1 - src/editor/manager.ts | 42 ++++++------------- src/lang/KclSingleton.ts | 35 ++++++++++++---- src/lang/std/sketch.test.ts | 2 +- 7 files changed, 44 insertions(+), 70 deletions(-) delete mode 100644 packages/codemirror-lsp-client/src/plugin/lint.ts diff --git a/e2e/playwright/flow-tests.spec.ts b/e2e/playwright/flow-tests.spec.ts index b0b8c3ec7..379fa716d 100644 --- a/e2e/playwright/flow-tests.spec.ts +++ b/e2e/playwright/flow-tests.spec.ts @@ -925,10 +925,10 @@ test.describe('Editor tests', () => { await expect(page.locator('.cm-lint-marker-error')).toBeVisible() await expect( - page.locator('.cm-lintRange.cm-lintRange-error').first() + page.locator('.cm-lint-marker.cm-lint-marker-error') ).toBeVisible() - await page.locator('.cm-lintRange.cm-lintRange-error').hover() + await page.locator('.cm-lint-marker.cm-lint-marker-error').hover() await expect(page.locator('.cm-diagnosticText').first()).toBeVisible() await expect( page.getByText('Cannot redefine `topAng`').first() @@ -1045,7 +1045,7 @@ test.describe('Editor tests', () => { await page.hover('.cm-lint-marker-error') const searchText = 'sketch profile must lie entirely on one side of the revolution axis' - await expect(page.getByText(searchText).first()).toBeVisible() + await expect(page.getByText(searchText)).toBeVisible() }) test.describe('Autocomplete works', () => { test('with enter/click to accept the completion', async ({ page }) => { diff --git a/packages/codemirror-lsp-client/src/plugin/lint.ts b/packages/codemirror-lsp-client/src/plugin/lint.ts deleted file mode 100644 index f0ce8c8ed..000000000 --- a/packages/codemirror-lsp-client/src/plugin/lint.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Extension } from '@codemirror/state' -import { linter, forEachDiagnostic, Diagnostic } from '@codemirror/lint' - -export default function lspLintExt(): Extension { - return linter((view) => { - let diagnostics: Diagnostic[] = [] - forEachDiagnostic(view.state, (d: Diagnostic, from: number, to: number) => { - diagnostics.push(d) - }) - return diagnostics - }) -} diff --git a/packages/codemirror-lsp-client/src/plugin/lsp.ts b/packages/codemirror-lsp-client/src/plugin/lsp.ts index b0350bb43..9c628264d 100644 --- a/packages/codemirror-lsp-client/src/plugin/lsp.ts +++ b/packages/codemirror-lsp-client/src/plugin/lsp.ts @@ -36,7 +36,6 @@ import lspAutocompleteExt from './autocomplete' import lspHoverExt from './hover' import lspFormatExt from './format' import lspIndentExt from './indent' -import lspLintExt from './lint' import lspSemanticTokensExt from './semantic-tokens' const useLast = (values: readonly any[]) => values.reduce((_, v) => v, '') @@ -216,20 +215,6 @@ export class LanguageServerPlugin implements PluginValue { if (!this.client.ready) return - // TODO(paultag): This is the *wrong* place for this to live. - // - // We need to clear diagnostics before updating the code, because - // if the code shrinks, the errors/diagnostics can go out of range - // of the source code, which cause an exception, breaking all the - // things. - // - // We need some sort of clear diagnostics boolean on the editor - // and we can drop this. - this.view.dispatch({ - effects: [setDiagnosticsEffect.of([])], - annotations: [], - }) - try { // Update the state (not the editor) with the new code. this.client.textDocumentDidChange({ @@ -587,7 +572,6 @@ export class LanguageServerPluginSpec lspFormatExt(plugin), lspHoverExt(plugin), lspIndentExt(), - lspLintExt(), lspSemanticTokensExt(), ] } diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index 9a0de6697..c2dfbfe0d 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -72,7 +72,6 @@ import { err, trap } from 'lib/trap' import { useCommandsContext } from 'hooks/useCommandsContext' import { modelingMachineEvent } from 'editor/manager' import { hasValidFilletSelection } from 'lang/modifyAst/addFillet' -import { uuidv4 } from 'lib/utils' type MachineContext = { state: StateFrom diff --git a/src/editor/manager.ts b/src/editor/manager.ts index 4a25d3bc4..424f61a56 100644 --- a/src/editor/manager.ts +++ b/src/editor/manager.ts @@ -6,11 +6,7 @@ import { Selections, processCodeMirrorRanges, Selection } from 'lib/selections' import { undo, redo } from '@codemirror/commands' import { CommandBarMachineEvent } from 'machines/commandBarMachine' import { addLineHighlight, addLineHighlightEvent } from './highlightextension' -import { - forEachDiagnostic, - Diagnostic, - setDiagnosticsEffect, -} from '@codemirror/lint' +import { Diagnostic, setDiagnosticsEffect } from '@codemirror/lint' const updateOutsideEditorAnnotation = Annotation.define() export const updateOutsideEditorEvent = updateOutsideEditorAnnotation.of(true) @@ -114,12 +110,20 @@ export default class EditorManager { } } - clearDiagnostics(): void { - this.setDiagnostics([]) - } - setDiagnostics(diagnostics: Diagnostic[]): void { if (!this._editorView) return + // Clear out any existing diagnostics that are the same. + for (const diagnostic of diagnostics) { + for (const otherDiagnostic of diagnostics) { + if (diagnosticIsEqual(diagnostic, otherDiagnostic)) { + diagnostics = diagnostics.filter( + (d) => !diagnosticIsEqual(d, diagnostic) + ) + diagnostics.push(diagnostic) + break + } + } + } this._editorView.dispatch({ effects: [setDiagnosticsEffect.of(diagnostics)], @@ -131,26 +135,6 @@ export default class EditorManager { }) } - addDiagnostics(diagnostics: Diagnostic[]): void { - if (!this._editorView) return - - forEachDiagnostic(this._editorView.state, function (diag) { - diagnostics.push(diag) - }) - - const uniqueDiagnostics = new Set() - diagnostics.forEach((diagnostic) => { - for (const knownDiagnostic of uniqueDiagnostics.values()) { - if (diagnosticIsEqual(diagnostic, knownDiagnostic)) { - return - } - } - uniqueDiagnostics.add(diagnostic) - }) - - this.setDiagnostics([...uniqueDiagnostics]) - } - undo() { if (this._editorView) { undo(this._editorView) diff --git a/src/lang/KclSingleton.ts b/src/lang/KclSingleton.ts index 0d9de4f44..1c0a2c9c6 100644 --- a/src/lang/KclSingleton.ts +++ b/src/lang/KclSingleton.ts @@ -17,6 +17,7 @@ import { } from 'lang/wasm' import { getNodeFromPath } from './queryAst' import { codeManager, editorManager, sceneInfra } from 'lib/singletons' +import { Diagnostic } from '@codemirror/lint' export class KclManager { private _ast: Program = { @@ -32,6 +33,7 @@ export class KclManager { } private _programMemory: ProgramMemory = ProgramMemory.empty() private _logs: string[] = [] + private _lints: Diagnostic[] = [] private _kclErrors: KCLError[] = [] private _isExecuting = false private _wasmInitFailed = true @@ -72,16 +74,36 @@ export class KclManager { this._logsCallBack(logs) } + get lints() { + return this._lints + } + + set lints(lints) { + if (lints === this._lints) return + this._lints = lints + // Run the lints through the diagnostics. + this.kclErrors = this._kclErrors + } + get kclErrors() { return this._kclErrors } set kclErrors(kclErrors) { + if (kclErrors === this._kclErrors && this.lints.length === 0) return this._kclErrors = kclErrors let diagnostics = kclErrorsToDiagnostics(kclErrors) - editorManager.addDiagnostics(diagnostics) + if (this.lints.length > 0) { + diagnostics = diagnostics.concat(this.lints) + } + editorManager.setDiagnostics(diagnostics) this._kclErrorsCallBack(kclErrors) } + addKclErrors(kclErrors: KCLError[]) { + if (kclErrors.length === 0) return + this.kclErrors = this.kclErrors.concat(kclErrors) + } + get isExecuting() { return this._isExecuting } @@ -148,12 +170,12 @@ export class KclManager { safeParse(code: string): Program | null { const ast = parse(code) + this.lints = [] this.kclErrors = [] if (!err(ast)) return ast const kclerror: KCLError = ast as KCLError - console.error('error parsing code', kclerror) - this.kclErrors = [kclerror] + this.addKclErrors([kclerror]) // TODO: re-eval if session should end? if (kclerror.msg === 'file is empty') this.engineCommandManager?.endSession() @@ -196,7 +218,7 @@ export class KclManager { engineCommandManager: this.engineCommandManager, }) - editorManager.addDiagnostics(await lintAst({ ast: ast })) + this.lints = await lintAst({ ast: ast }) sceneInfra.modelingSend({ type: 'code edit during sketch' }) defaultSelectionFilter(programMemory, this.engineCommandManager) @@ -228,7 +250,7 @@ export class KclManager { return } this.logs = logs - this.kclErrors = errors + this.addKclErrors(errors) this.programMemory = programMemory this.ast = { ...ast } this._executeCallback() @@ -272,8 +294,6 @@ export class KclManager { useFakeExecutor: true, }) - editorManager.addDiagnostics(await lintAst({ ast: ast })) - this._logs = logs this._kclErrors = errors this._programMemory = programMemory @@ -305,7 +325,6 @@ export class KclManager { }) } async executeCode(zoomToFit?: boolean): Promise { - console.log('[kcl/KclSingleton] executeCode') const ast = this.safeParse(codeManager.code) if (!ast) { this.clearAst() diff --git a/src/lang/std/sketch.test.ts b/src/lang/std/sketch.test.ts index 397d3c228..e5735f4c8 100644 --- a/src/lang/std/sketch.test.ts +++ b/src/lang/std/sketch.test.ts @@ -211,7 +211,7 @@ describe('testing addTagForSketchOnFace', () => { ` const code = genCode(originalLine) const ast = parse(code) - const programMemory = await enginelessExecutor(ast) + await enginelessExecutor(ast) const sourceStart = code.indexOf(originalLine) const sourceRange: [number, number] = [ sourceStart,