Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6517,7 +6517,6 @@
"devDependencies": {
"@octokit/rest": "^20.1.1",
"@types/glob": "^7.2.0",
"@types/minimatch": "^3.0.5",
"@types/mocha": "^10.0.6",
"@types/node": "^20.14.2",
"@types/node-fetch": "^2.6.11",
Expand Down Expand Up @@ -6569,7 +6568,7 @@
"comment-json": "^4.2.3",
"escape-string-regexp": "^2.0.0",
"glob": "^7.2.3",
"minimatch": "^3.0.5",
"minimatch": "^4.2.0",
"mkdirp": "^3.0.1",
"node-fetch": "^2.7.0",
"node-loader": "^2.0.0",
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,8 @@ export class DefaultClient implements Client {
}
let foundGlobMatch: boolean = false;
for (const assoc in assocs) {
if (minimatch(filePath, assoc)) {
const matcher = new minimatch.Minimatch(assoc);
if (matcher.match(filePath)) {
foundGlobMatch = true;
break; // Assoc matched a glob pattern.
}
Expand Down
43 changes: 33 additions & 10 deletions Extension/src/LanguageServer/editorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
'use strict';

import * as fs from 'fs';
import { Minimatch } from 'minimatch';
import * as path from 'path';
import { isWindows } from '../constants';

export const cachedEditorConfigSettings: Map<string, any> = new Map<string, any>();

Expand Down Expand Up @@ -61,13 +63,25 @@
return "never";
}

function matchesSection(filePath: string, section: string): boolean {
const fileName: string = path.basename(filePath);
// Escape all regex special characters except '*' and '?'.
// Convert wildcards '*' to '.*' and '?' to '.'.
const sectionPattern = section.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.');
const regex: RegExp = new RegExp(`^${sectionPattern}$`);
return regex.test(fileName);
export function matchesSection(pathPrefix: string, filePath: string, section: string): boolean {
// The following code is copied from: https://github.com/editorconfig/editorconfig-core-js
const matchOptions = { matchBase: true, dot: true };
pathPrefix = pathPrefix.replace(/[?*+@!()|[\]{}]/g, '\\$&');
pathPrefix = pathPrefix.replace(/^#/, '\\#');
switch (section.indexOf('/')) {
case -1:
section = `**/${section}`;
break;
case 0:
section = section.substring(1);
break;
default:
break;
}
section = section.replace(/\\\\/g, '\\\\\\\\');
section = section.replace(/\*\*/g, '{*,**/**/**}');
const matcher = new Minimatch(`${pathPrefix}/${section}`, matchOptions);
return matcher.match(filePath);
}

function parseEditorConfigContent(content: string): Record<string, any> {
Expand Down Expand Up @@ -95,9 +109,9 @@
let value: any = values.join('=').trim();

// Convert boolean-like and numeric values.
if (value.toLowerCase() === 'true') {
if (value === 'true') {
value = true;
} else if (value.toLowerCase() === 'false') {
} else if (value === 'false') {
value = false;
} else if (!isNaN(Number(value))) {
value = Number(value);
Expand All @@ -123,6 +137,10 @@
let currentDir: string = path.dirname(filePath);
const rootDir: string = path.parse(currentDir).root;

if (isWindows) {
filePath = filePath.replace(/\\/g, '/');
}

// Traverse from the file's directory to the root directory.
for (; ;) {
const editorConfigPath: string = path.join(currentDir, '.editorconfig');
Expand All @@ -138,9 +156,14 @@
};
}

let currentDirForwardSlashes: string = currentDir;
if (isWindows) {
currentDirForwardSlashes = currentDir.replace(/\\/g, '/');
}

// Match sections and combine configurations.
Object.keys(configData).forEach((section: string) => {
if (section !== '*' && matchesSection(filePath, section)) {
if (section !== '*' && matchesSection(currentDirForwardSlashes, filePath, section)) {
combinedConfig = {
...combinedConfig,
...configData[section]
Expand Down
9 changes: 8 additions & 1 deletion Extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha1-B1CLRXl8uB7D8nMBGwVM0HVe3co=

"@types/minimatch@^3.0.3", "@types/minimatch@^3.0.5":
"@types/minimatch@^3.0.3":
version "3.0.5"
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
integrity sha1-EAHMXmo3BLg8I2An538vWOoBD0A=
Expand Down Expand Up @@ -3278,6 +3278,13 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimatch@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-4.2.3.tgz#b4dcece1d674dee104bb0fb833ebb85a78cbbca6"
integrity sha512-lIUdtK5hdofgCTu3aT0sOaHsYR37viUuIc0rwnnDXImbwFRcumyLMeZaM0t0I/fgxS6s6JMfu0rLD1Wz9pv1ng==
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1, minimatch@^5.1.0, minimatch@^5.1.6:
version "5.1.6"
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
Expand Down
Loading