scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.65k stars 192 forks source link

controlling linting from a button click #311

Open hjangir154 opened 7 months ago

hjangir154 commented 7 months ago

I have case where I need to update the linting error messages from a button click outside the codeMirror component. Although values are updating it wont show up on the editor until i manually update the text inside the editor by typing.

I tried following

  1. refresh editor using instance
  2. updating value prop: value get's updated but linting wont show up
  3. calling forceRefresh() method on component
{
    "mode": "text/x-hive",
    "indentWithTabs": false,
    "lineWrapping": true,
    "lineNumbers": true,
    "gutters": [
        "CodeMirror-lint-markers"
    ],
    "extraKeys": {
        "Ctrl-Space": "autocomplete",
        "Ctrl-/": "toggleComment"
    },
    "indentUnit": 2,
    "theme": "default",
    "matchBrackets": true,
    "autoCloseBrackets": true,
    "highlightSelectionMatches": true,
    "cursorBlinkRate": 530,
    "lint": {
        "async": true,
        "delay": 1000,
         "getAnnotations" : (text, onComplete, _, editor) => {…}
    },
    "tabSize": 2
}

this is the option object i am passing in,

(text: string, onComplete, _, editor) => {
    if ((text || '').length === 0) {
        return;
    }
    function complete(options: []) {
        console.log("OPTIONS inside", options, suggetions)
        onComplete(options.concat(suggetions));
        editor?.refresh();
    }
    console.log("GetAnnotationCalled", suggetions)
    getSqlLintAnnotationsDebounced(text, language, complete);
}

image