Skip to content

Commit

Permalink
Fix pattern matching under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumer committed Dec 13, 2019
1 parent 9a465ac commit 46ea301
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
25 changes: 13 additions & 12 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
WorkspaceFolder,
} from 'vscode-languageclient';

import { findEslint, convert2RegExp, toOSPath } from './utils';
import { findEslint, convert2RegExp, toOSPath, toPosixPath } from './utils';
import { TaskProvider } from './tasks';
import { WorkspaceConfiguration } from 'vscode';

Expand Down Expand Up @@ -978,23 +978,24 @@ function realActivate(context: ExtensionContext): void {
if (directory !== undefined || pattern !== undefined) {
const filePath = document.uri.scheme === 'file' ? document.uri.fsPath : undefined;
if (filePath !== undefined) {
const normalize = (value: string): string => {
value = toOSPath(value);
if (!path.isAbsolute(value) && workspaceFolderPath !== undefined) {
value = path.join(workspaceFolderPath, value);
if (directory !== undefined) {
directory = toOSPath(directory);
if (!path.isAbsolute(directory) && workspaceFolderPath !== undefined) {
directory = path.join(workspaceFolderPath, directory);
}
if (value.charAt(value.length - 1) !== path.sep) {
value = value + path.sep;
if (directory.charAt(directory.length - 1) !== path.sep) {
directory = directory + path.sep;
}
return value;
};
if (directory !== undefined) {
directory = normalize(directory);
if (filePath.startsWith(directory)) {
itemValue = directory;
}
} else if (pattern !== undefined && pattern.length > 0) {
pattern = normalize(pattern);
if (!path.posix.isAbsolute(pattern) && workspaceFolderPath !== undefined) {
pattern = path.posix.join(toPosixPath(workspaceFolderPath), pattern);
}
if (pattern.charAt(pattern.length - 1) !== path.posix.sep) {
pattern = pattern + path.posix.sep;
}
const regExp: RegExp | undefined = convert2RegExp(pattern);
if (regExp !== undefined) {
const match = regExp.exec(filePath);
Expand Down
7 changes: 7 additions & 0 deletions client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,11 @@ export function toOSPath(path: string): string {
} else {
return path;
}
}

export function toPosixPath(path: string): string {
if (process.platform !== 'win32') {
return path;
}
return path.replace(/\\/g, '/');
}

0 comments on commit 46ea301

Please sign in to comment.