From ff1b75c3f35ceb2e997d0f08f865171e61200e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20James?= Date: Sun, 3 Mar 2024 22:34:15 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Add=20a=20command=20to=20force?= =?UTF-8?q?=20linter=20update=20(#121)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeMirror6/Models/CodeMirrorSimpleCommand.cs | 4 ++++ CodeMirror6/NodeLib/src/CmInstance.ts | 1 + CodeMirror6/NodeLib/src/CmLint.ts | 21 ++++++++++++++++--- CodeMirror6/NodeLib/src/index.ts | 7 +++++-- Examples.Common/Example.razor | 7 +++++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CodeMirror6/Models/CodeMirrorSimpleCommand.cs b/CodeMirror6/Models/CodeMirrorSimpleCommand.cs index e05bee29..078c97a4 100644 --- a/CodeMirror6/Models/CodeMirrorSimpleCommand.cs +++ b/CodeMirror6/Models/CodeMirrorSimpleCommand.cs @@ -204,4 +204,8 @@ public enum CodeMirrorSimpleCommand /// Delete the trailing whitespace /// DeleteTrailingWhitespace, + /// + /// Refresh the linter + /// + RequestLinterRefresh, } diff --git a/CodeMirror6/NodeLib/src/CmInstance.ts b/CodeMirror6/NodeLib/src/CmInstance.ts index 57bdce4f..d3b3c449 100644 --- a/CodeMirror6/NodeLib/src/CmInstance.ts +++ b/CodeMirror6/NodeLib/src/CmInstance.ts @@ -14,6 +14,7 @@ export class CmInstance public view: EditorView public setup: CmSetup public config: CmConfiguration + public lintRefreshRequested: boolean = false public languageCompartment: Compartment = new Compartment public markdownStylingCompartment: Compartment = new Compartment public tabSizeCompartment: Compartment = new Compartment diff --git a/CodeMirror6/NodeLib/src/CmLint.ts b/CodeMirror6/NodeLib/src/CmLint.ts index 9fdeada0..63f6de2a 100644 --- a/CodeMirror6/NodeLib/src/CmLint.ts +++ b/CodeMirror6/NodeLib/src/CmLint.ts @@ -1,10 +1,13 @@ import { Diagnostic } from "@codemirror/lint" +import { ViewUpdate } from "@codemirror/view" import { DotNet } from "@microsoft/dotnet-js-interop" import { EditorView } from "codemirror" + import { consoleLog } from "./CmLogging" +import { CMInstances } from './CmInstance' /** - * A function that fetches diagnostics from the Blazor component. + * Fetch diagnostics from the Blazor component */ export async function externalLintSource(id: string, view: EditorView, dotnetHelper: DotNet.DotNetObject): Promise { try { @@ -19,10 +22,18 @@ export async function externalLintSource(id: string, view: EditorView, dotnetHel } } +/** + * Request a linter refresh. Linting is always re-done on document changes. + */ +export function requestLinterRefresh(id: string) { + consoleLog(id, `Linter refresh requested for Id ${id}`) + CMInstances[id].lintRefreshRequested = true +} + /** * A function that fetches the linter configuration */ -export function getExternalLinterConfig(): any { +export function getExternalLinterConfig(id: string): any { return { /** Time to wait (in milliseconds) after a change before running @@ -34,7 +45,11 @@ export function getExternalLinterConfig(): any { need to be recomputed. Linting is always re-done on document changes. */ - needsRefresh: null, + needsRefresh: (update: ViewUpdate) => { + const lintRefreshRequested = CMInstances[id].lintRefreshRequested + CMInstances[id].lintRefreshRequested = false + return lintRefreshRequested + }, /** Optional filter to determine which diagnostics produce markers in the content. diff --git a/CodeMirror6/NodeLib/src/index.ts b/CodeMirror6/NodeLib/src/index.ts index e5895b2c..8ebdc77a 100644 --- a/CodeMirror6/NodeLib/src/index.ts +++ b/CodeMirror6/NodeLib/src/index.ts @@ -39,7 +39,7 @@ import { cut, copy, paste, } from "./CmCommands" import { dynamicImagesExtension } from "./CmImages" -import { externalLintSource, getExternalLinterConfig } from "./CmLint" +import { externalLintSource, getExternalLinterConfig, requestLinterRefresh } from "./CmLint" import { CmSetup } from "./CmSetup" import { replaceEmojiExtension, lastOperationWasUndo } from "./CmEmojiReplace" import { blockquote } from "./CmBlockquote" @@ -61,6 +61,7 @@ import { createEditorWithId } from "./CmId" import { hyperLink } from './CmHyperlink' export { getCmInstance } +export { requestLinterRefresh } /** * Initialize a new CodeMirror instance @@ -167,7 +168,7 @@ export async function initCodeMirror( if (setup.highlightSelectionMatches === true) extensions.push(highlightSelectionMatches()) if (setup.allowMultipleSelections === true) extensions.push(EditorState.allowMultipleSelections.of(true)) if (initialConfig.lintingEnabled === true || setup.bindValueMode == "OnDelayedInput") { - extensions.push(linter(async view => await externalLintSource(id, view, dotnetHelper), getExternalLinterConfig())) + extensions.push(linter(async view => await externalLintSource(id, view, dotnetHelper), getExternalLinterConfig(id))) } if (initialConfig.lintingEnabled === true) extensions.push(lintGutter()) @@ -534,6 +535,8 @@ export function dispatchCommand(id: string, functionName: string, ...args: any[] case 'ClearLocalStorage': clearLocalStorage(id); break; case 'ScrollIntoView': view.dispatch({ scrollIntoView: true }); break; + case 'RequestLinterRefresh': requestLinterRefresh(id); break; + default: throw new Error(`Function ${functionName} does not exist.`); } view.focus() diff --git a/Examples.Common/Example.razor b/Examples.Common/Example.razor index 9d9410d1..0cdf1f89 100644 --- a/Examples.Common/Example.razor +++ b/Examples.Common/Example.razor @@ -113,6 +113,13 @@ }) >Scroll into view + + Date: Sun, 3 Mar 2024 22:34:26 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20Update=20changelog=20for=200?= =?UTF-8?q?.8.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ NEW_CHANGELOG.md | 13 ++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f27a34..63967d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.8.0 - 2024-03-03 + +### ✨ Introduce new features + +- Add a command to force linter update (#121) + ## 0.7.5 - 2024-03-03 ### 🎨 Improve structure / format of the code diff --git a/NEW_CHANGELOG.md b/NEW_CHANGELOG.md index d9835df4..fc26c79d 100644 --- a/NEW_CHANGELOG.md +++ b/NEW_CHANGELOG.md @@ -1,12 +1,3 @@ -### 🎨 Improve structure / format of the code +### ✨ Introduce new features -- Minor cleanup -- Use integrated support for multiple cursors - -### ⬆️ Upgrade dependencies - -- Update js dependencies - -### 🚨 Fix compiler / linter warnings - -- Fix warning in example project Upload endpoint +- Add a command to force linter update (#121) From 0ecf81e0bc8f518aa75302307be02a4129e0e0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20James?= Date: Sun, 3 Mar 2024 22:34:26 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=96=20Bump=20version=20to=200.8.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeMirror6/CodeMirror6.csproj | 2 +- Examples.BlazorServer/Examples.BlazorServer.csproj | 2 +- .../Examples.BlazorServerInteractive.csproj | 2 +- Examples.BlazorWasm/Examples.BlazorWasm.csproj | 2 +- Examples.Common/Examples.Common.csproj | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CodeMirror6/CodeMirror6.csproj b/CodeMirror6/CodeMirror6.csproj index e7812bc3..a11c81df 100644 --- a/CodeMirror6/CodeMirror6.csproj +++ b/CodeMirror6/CodeMirror6.csproj @@ -9,7 +9,7 @@ GaelJ.BlazorCodeMirror6 true GaelJ.BlazorCodeMirror6 - 0.7.5 + 0.8.0 true snupkg true diff --git a/Examples.BlazorServer/Examples.BlazorServer.csproj b/Examples.BlazorServer/Examples.BlazorServer.csproj index 1c6be4d9..90c3154a 100644 --- a/Examples.BlazorServer/Examples.BlazorServer.csproj +++ b/Examples.BlazorServer/Examples.BlazorServer.csproj @@ -4,7 +4,7 @@ enable false enable - 0.7.5 + 0.8.0 diff --git a/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj b/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj index aff8e3df..fef47187 100644 --- a/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj +++ b/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj @@ -4,7 +4,7 @@ enable enable false - 0.7.5 + 0.8.0 diff --git a/Examples.BlazorWasm/Examples.BlazorWasm.csproj b/Examples.BlazorWasm/Examples.BlazorWasm.csproj index fbe8eda2..82a86291 100644 --- a/Examples.BlazorWasm/Examples.BlazorWasm.csproj +++ b/Examples.BlazorWasm/Examples.BlazorWasm.csproj @@ -4,7 +4,7 @@ enable enable false - 0.7.5 + 0.8.0 diff --git a/Examples.Common/Examples.Common.csproj b/Examples.Common/Examples.Common.csproj index 9090bf89..a2253fb0 100644 --- a/Examples.Common/Examples.Common.csproj +++ b/Examples.Common/Examples.Common.csproj @@ -5,7 +5,7 @@ enable enable false - 0.7.5 + 0.8.0