vscode-todo-highlight icon indicating copy to clipboard operation
vscode-todo-highlight copied to clipboard

todohighlight.include does not work?

Open dienluong opened this issue 3 years ago • 1 comments

Hi,

I can't figure this out. I only have the follow custom settings in user's settings.json:

    "todohighlight.include": [
        "**/*.log"
    ],
    "todohighlight.keywords": [
        {
            "text": "error",
            "color": "white",
            "backgroundColor": "red",
        },
    ],
    "todohighlight.isCaseSensitive": false

I just want highlighting only on file with .log extension. But still highlighting seems to be applied to all files, including this very settings.json.

Extension version: 1.0.5 Visual Studio Code 1.68.1

dienluong avatar Jun 22 '22 09:06 dienluong

hello ! Check Workspace Settings: Sometimes, workspace-specific settings might override user settings. Check if there are any todohighlight.include settings defined at the workspace level that might include more file types. Extension Defaults: Verify if the extension itself has default settings that include other file types. You might need to explicitly exclude other file types if that's the case. If the settings are correctly specified but not respected, you might need to look into the extension's code. Here is a modification to ensure that the extension checks the file extension before applying decorations.

File to Modify: Typically in the main extension file, possibly extension.js.

Code to Add:

First, you need to make sure that the function responsible for triggering updates to decorations checks the file type

function triggerUpdateDecorations() { if (activeEditor && isLogFile(activeEditor.document.fileName)) { updateDecorations(); } }

function isLogFile(fileName) { return fileName.endsWith('.log'); } Check that your extension reloads its configuration when the settings change and correctly initializes when activated:function activate(context) { vscode.workspace.onDidChangeConfiguration(handleConfigurationChange); updateDecorations(); // other setup code... }

function handleConfigurationChange(event) { if (event.affectsConfiguration("todohighlight.include") || event.affectsConfiguration("todohighlight.keywords")) { updateDecorations(); // Reapply with new settings } } Additional Checks Clear Cache/State: Sometimes, extensions might cache an old state; consider adding functionality to clear such states when configurations change. Testing: After making these changes, test across multiple files to ensure the rules are applied only to .log files.

SaharBahloul avatar Apr 22 '24 22:04 SaharBahloul