Skip to content

Commit

Permalink
Merge branch 'develop' into fix_hsl_new_syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiKillertO authored Nov 8, 2024
2 parents e96b3a0 + 2257c91 commit 3ba76ad
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json'],
},
extends: [
'plugin:@typescript-eslint/recommended-type-checked',
Expand Down
147 changes: 102 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"lint": "eslint .",
"test": "npm run vscode:prepublish && node ./out/test/runTest.js"
},
"devDependencies": {
"@types/chai": "5.0.0",
"@types/glob": "^8.1.0",
"@types/glob-to-regexp": "^0.4.4",
"@types/mocha": "^10.0.9",
"@types/node": "^12.0.0",
"@types/vscode": "^1.54.0",
Expand All @@ -208,6 +208,6 @@
"typescript": "^5.6.2"
},
"dependencies": {
"glob-to-regexp": "^0.4.1"
"minimatch": "^10.0.1"
}
}
29 changes: 22 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import Queue from './lib/queue';
import VariablesManager from './lib/variables/variables-manager';
import CacheManager from './lib/cache-manager';
import EditorManager from './lib/editor-manager';
import globToRegexp from 'glob-to-regexp';
import {
getColorizeConfig,
ColorizeConfig,
generateDecorationType,
} from './lib/colorize-config';

import Listeners from './listeners';
import { minimatch } from 'minimatch';

let config: ColorizeConfig = {
languages: [],
Expand Down Expand Up @@ -213,10 +213,24 @@ function isLanguageSupported(languageId: string): boolean {
* @returns {boolean}
*/
function isIncludedFile(fileName: string): boolean {
return (
config.filesToIncludes.find((globPattern: string) =>
globToRegexp(globPattern).test(fileName),
) !== undefined
return config.filesToIncludes.some((globPattern: string) =>
// No reason why this reports an error
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
minimatch(fileName, globPattern, { nonegate: true }),
);
}

/**
* Check if the file is the `colorize.exclude` setting
*
* @param {string} fileName A valid filename (path to the file)
* @returns {boolean}
*/
function isExcludedFile(fileName: string): boolean {
return config.filesToExcludes.some((globPattern: string) =>
// No reason why this reports an error
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
minimatch(fileName, globPattern, { nonegate: true }),
);
}

Expand All @@ -229,8 +243,9 @@ function isIncludedFile(fileName: string): boolean {
function canColorize(document: TextDocument): boolean {
// update to use filesToExcludes. Remove `isLanguageSupported` ? checking path with file extension or include glob pattern should be enough
return (
isLanguageSupported(document.languageId) ||
isIncludedFile(document.fileName)
!isExcludedFile(document.fileName) &&
(isLanguageSupported(document.languageId) ||
isIncludedFile(document.fileName))
);
}

Expand Down
Loading

0 comments on commit 3ba76ad

Please sign in to comment.