Skip to content

Commit 0394b99

Browse files
authored
Merge pull request #6380 from dibarbet/fix_issubfolderof
Fix isSubfolderOf to correctly determine if a folder is a subfolder
2 parents 920f08a + c97edb5 commit 0394b99

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

omnisharptest/omnisharpUnitTests/common.test.ts renamed to omnisharptest/omnisharpJestTests/common.test.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,79 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { describe, test, expect } from '@jest/globals';
67
import * as path from 'path';
78

89
import { isSubfolderOf, safeLength, sum } from '../../src/common';
910

10-
import { should, expect } from 'chai';
11-
12-
suite('Common', () => {
13-
suiteSetup(() => should());
14-
15-
suite('safeLength', () => {
11+
describe('Common', () => {
12+
describe('safeLength', () => {
1613
test('return 0 for empty array', () => {
1714
const array: any[] = [];
1815
const result = safeLength(array);
19-
result.should.equal(0);
16+
expect(result).toBe(0);
2017
});
2118

2219
test('returns 5 for array of 5 elements', () => {
2320
const array = [1, 2, 3, 4, 5];
2421
const result = safeLength(array);
25-
result.should.equal(5);
22+
expect(result).toBe(5);
2623
});
2724

2825
test('returns 0 for undefined', () => {
2926
const array = undefined;
3027
const result = safeLength(array);
31-
result.should.equal(0);
28+
expect(result).toBe(0);
3229
});
3330
});
3431

35-
suite('sum', () => {
32+
describe('sum', () => {
3633
test('produce total from numbers', () => {
3734
const array = [1, 2, 3, 4, 5];
3835
const result = sum(array, (i) => i);
39-
result.should.equal(15);
36+
expect(result).toBe(15);
4037
});
4138

4239
test('produce total from lengths of arrays', () => {
4340
const array = [[1, 2], [3], [], [4, 5, 6]];
4441
const result = sum(array, (i) => i.length);
45-
result.should.equal(6);
42+
expect(result).toBe(6);
4643
});
4744

4845
test('produce total of true values from array of booleans', () => {
4946
const array = [true, false, false, true, true, true, false, true];
5047
const result = sum(array, (b) => (b ? 1 : 0));
51-
result.should.equal(5);
48+
expect(result).toBe(5);
5249
});
5350
});
5451

55-
suite('isSubfolderOf', () => {
52+
describe('isSubfolderOf', () => {
5653
test('same paths', () => {
5754
const subfolder: string = ['C:', 'temp', 'VS', 'dotnetProject'].join(path.sep);
5855
const folder: string = ['C:', 'temp', 'VS', 'dotnetProject'].join(path.sep);
5956

60-
expect(isSubfolderOf(subfolder, folder)).to.be.true;
57+
expect(isSubfolderOf(subfolder, folder)).toBe(true);
6158
});
6259

6360
test('correct subfolder', () => {
64-
const subfolder: string = ['C:', 'temp', 'VS'].join(path.sep);
65-
const folder: string = ['C:', 'temp', 'VS', 'dotnetProject'].join(path.sep);
61+
const folder: string = ['C:', 'temp', 'VS'].join(path.sep);
62+
const subfolder: string = ['C:', 'temp', 'VS', 'dotnetProject'].join(path.sep);
6663

67-
expect(isSubfolderOf(subfolder, folder)).to.be.true;
64+
expect(isSubfolderOf(subfolder, folder)).toBe(true);
6865
});
6966

70-
test('longer subfolder', () => {
71-
const subfolder: string = ['C:', 'temp', 'VS', 'a', 'b', 'c'].join(path.sep);
72-
const folder: string = ['C:', 'temp', 'VS'].join(path.sep);
67+
test('longer folder', () => {
68+
const folder: string = ['C:', 'temp', 'VS', 'a', 'b', 'c'].join(path.sep);
69+
const subfolder: string = ['C:', 'temp', 'VS'].join(path.sep);
7370

74-
expect(isSubfolderOf(subfolder, folder)).to.be.false;
71+
expect(isSubfolderOf(subfolder, folder)).toBe(false);
7572
});
7673

7774
test('Different drive', () => {
7875
const subfolder: string = ['C:', 'temp', 'VS'].join(path.sep);
7976
const folder: string = ['E:', 'temp', 'VS'].join(path.sep);
8077

81-
expect(isSubfolderOf(subfolder, folder)).to.be.false;
78+
expect(isSubfolderOf(subfolder, folder)).toBe(false);
8279
});
8380
});
8481
});

src/common.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,21 @@ export function convertNativePathToPosix(pathString: string): string {
186186
}
187187

188188
/**
189-
* This function checks to see if a subfolder is part of folder.
189+
* This function checks to see if a subfolder is part of a parent folder.
190190
*
191-
* Assumes subfolder and folder are absolute paths and have consistent casing.
191+
* Assumes subfolder and parent folder are absolute paths and have consistent casing.
192192
*
193-
* @param subfolder subfolder to check if it is part of the folder parameter
194-
* @param folder folder to check aganist
193+
* @param subfolder subfolder to check if it is part of the parent folder parameter
194+
* @param parentFolder folder to check aganist
195195
*/
196-
export function isSubfolderOf(subfolder: string, folder: string): boolean {
196+
export function isSubfolderOf(subfolder: string, parentFolder: string): boolean {
197197
const subfolderArray: string[] = subfolder.split(path.sep);
198-
const folderArray: string[] = folder.split(path.sep);
198+
const parentFolderArray: string[] = parentFolder.split(path.sep);
199199

200200
// Check to see that every sub directory in subfolder exists in folder.
201201
return (
202-
subfolderArray.length <= folderArray.length &&
203-
subfolderArray.every((subpath, index) => folderArray[index] === subpath)
202+
parentFolderArray.length <= subfolder.length &&
203+
parentFolderArray.every((subpath, index) => subfolderArray[index] === subpath)
204204
);
205205
}
206206

src/omnisharpWorkspaceDebugInformationProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ export class OmnisharpWorkspaceDebugInformationProvider implements IWorkspaceDeb
4444
* Note: serverUtils.requestWorkspaceInformation only retrieves one folder for multi-root workspaces. Therefore, generator will be incorrect for all folders
4545
* except the first in a workspace. Currently, this only works if the requested folder is the same as the server's solution path or folder.
4646
*/
47-
return projects?.filter((p) => {
47+
const projectsInWorkspace = projects?.filter((p) => {
4848
// Get absolute paths of current folder and server folder.
4949
const workspaceFolder = path.resolve(workspacePath.fsPath);
5050
const projectFolder = path.dirname(p.projectPath);
5151
return isSubfolderOf(projectFolder, workspaceFolder);
5252
});
53+
return projectsInWorkspace;
5354
}
5455
}

0 commit comments

Comments
 (0)