Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

todohighlight.include does not work? #213

Open
dienluong opened this issue Jun 22, 2022 · 1 comment
Open

todohighlight.include does not work? #213

dienluong opened this issue Jun 22, 2022 · 1 comment

Comments

@dienluong
Copy link

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

@SaharBahloul
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants