Skip to content

Commit

Permalink
Fix corner case with test file discovery (#301)
Browse files Browse the repository at this point in the history
* Fix corner case with test file discovery

* 0.16.10
  • Loading branch information
rvanasa authored Oct 14, 2024
1 parent b67351f commit 008822a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-motoko",
"displayName": "Motoko",
"description": "Motoko language support",
"version": "0.16.9",
"version": "0.16.10",
"publisher": "dfinity-foundation",
"repository": "https://github.com/dfinity/vscode-motoko",
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions src/common/watchConfig.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const watchGlob = '**/*.{mo,did,json,dhall,toml}';

export const ignoreGlobPatterns = [
'**/node_modules/**/*', // npm packages
'**/.vessel/.tmp/**/*', // temporary Vessel files
];
22 changes: 16 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
TestParams,
TestResult,
} from './common/connectionTypes';
import { watchGlob } from './common/watchConfig';
import { ignoreGlobPatterns, watchGlob } from './common/watchConfig';
import { formatDocument } from './formatter';

const config = workspace.getConfiguration('motoko');
Expand Down Expand Up @@ -232,14 +232,24 @@ function setupTests(context: ExtensionContext) {
controller.items.add(item);
testItemTypeMap.set(item, ItemType.File);
} catch (err) {
console.error(`Error while adding test file: ${uri}\n${err}`);
console.error(`Error while adding test file: ${uri}`);
console.error(err);
}
};
workspace.workspaceFolders?.forEach((workspaceFolder) => {
const directory = workspaceFolder.uri.fsPath;
glob.sync(pattern, { cwd: directory }).forEach((file) => {
addFile(Uri.file(path.resolve(directory, file)));
});
try {
const directory = workspaceFolder.uri.fsPath;
glob.sync(pattern, {
cwd: directory,
ignore: ignoreGlobPatterns,
followSymbolicLinks: false,
}).forEach((file) => {
addFile(Uri.file(path.resolve(directory, file)));
});
} catch (err) {
console.error('Error while loading test files:');
console.error(err);
}
});
watcher.onDidCreate(addFile, context.subscriptions);
watcher.onDidChange(addFile, context.subscriptions);
Expand Down
14 changes: 6 additions & 8 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ import {
TEST_FILE_REQUEST,
TestResult,
} from '../common/connectionTypes';
import { watchGlob as virtualFilePattern } from '../common/watchConfig';
import {
ignoreGlobPatterns,
watchGlob as virtualFilePattern,
} from '../common/watchConfig';
import icCandid from '../generated/aaaaa-aa.did';
import { globalASTCache } from './ast';
import {
Expand Down Expand Up @@ -103,11 +106,6 @@ interface MotokoSettings {
debugHover: boolean;
}

const ignoreGlobs = [
'**/node_modules/**/*', // npm packages
'**/.vessel/.tmp/**/*', // temporary Vessel files
];

const shouldHideWarnings = (uri: string) =>
uri.includes('/.vessel/') || uri.includes('/.mops/');

Expand Down Expand Up @@ -246,7 +244,7 @@ function notifyPackageConfigChange(reuseCached = false) {
const cwd = resolveFilePath(workspaceFolder.uri);
const paths = glob.sync(`**/{${filenames.join(',')}}`, {
cwd,
ignore: ignoreGlobs,
ignore: ignoreGlobPatterns,
dot: false,
followSymbolicLinks: false,
});
Expand Down Expand Up @@ -686,7 +684,7 @@ function notifyWorkspace() {
glob.sync(virtualFilePattern, {
cwd: folderPath,
dot: true,
ignore: ignoreGlobs,
ignore: ignoreGlobPatterns,
followSymbolicLinks: false,
}).forEach((relativePath) => {
const path = join(folderPath, relativePath);
Expand Down

0 comments on commit 008822a

Please sign in to comment.