diff --git a/README.md b/README.md index 3716a14..aae8362 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ This Visual Studio Code extension finds files related to the currently active ed - Works with named capture groups and numbered capture groups when substituting into target paths. - Default matchers setup for chromium source projects. +## Changelog + +- Extracted logging to a dedicated `src/logger.js` utility module. + ## Configuration The extension uses the `relatedsources.matchers` setting (an array) to discover related files. Each matcher is an object with the following properties: @@ -25,6 +29,10 @@ The extension uses the `relatedsources.matchers` setting (an array) to discover - `targetPath` (string) — a glob-style target pattern. Use `${name}` to substitute named capture groups or `${1}` for numbered groups. The pattern is interpreted relative to the workspace root. - `name` (string) — a friendly name for the matcher. +The extension also supports: + +- `relatedsources.slowMatcherThresholdMs` (number, default `1000`) — time in milliseconds a matcher can take before a warning notification is shown. Set to `0` to disable slow-matcher warnings. + Example settings (to add to your workspace or user settings): ```json diff --git a/package.json b/package.json index e2fff80..9a64ae5 100644 --- a/package.json +++ b/package.json @@ -120,6 +120,12 @@ ], "description": "Related source file patterns" }, + "relatedsources.slowMatcherThresholdMs": { + "type": "number", + "default": 1000, + "minimum": 0, + "description": "Time in milliseconds a matcher can take before a warning is shown. Set to 0 to disable warnings." + }, "relatedsources.openColumn": { "type": "string", "enum": [ diff --git a/src/extension.js b/src/extension.js index 1c3ddc7..02b5b6d 100644 --- a/src/extension.js +++ b/src/extension.js @@ -1,11 +1,10 @@ const vscode = require('vscode'); const path = require('path'); const { findFilesWithGlob } = require('./findFilesWithGlob'); +const { logger } = require('./logger'); let relatedSources = null; -const log = (...args) => { - console.log('[RelatedSources] ', ...args); -} +const log = (...args) => logger.log(...args); function activate(context) { log('extension is now active!'); @@ -209,6 +208,7 @@ class RelatedSources { const config = vscode.workspace.getConfiguration('relatedsources'); const matchers = config.matchers || []; + const slowMatcherThresholdMs = config.get('slowMatcherThresholdMs', 1000); let candidateUris = []; @@ -259,7 +259,7 @@ class RelatedSources { const matcherDuration = Date.now() - matcherStartTime; log(`Matcher "${matcherName}": completed in ${matcherDuration}ms`); - if (matcherDuration > 1000) { + if (slowMatcherThresholdMs > 0 && matcherDuration > slowMatcherThresholdMs) { vscode.window.showWarningMessage( `Related Sources: Matcher "${matcherName}" took ${(matcherDuration / 1000).toFixed(1)}s ` + `and findFiles duration ${(findFilesDuration / 1000).toFixed(1)}s. ` + diff --git a/src/logger.js b/src/logger.js new file mode 100644 index 0000000..35b16d0 --- /dev/null +++ b/src/logger.js @@ -0,0 +1,15 @@ +'use strict'; + +const PREFIX = '[RelatedSources]'; + +/** + * Simple logger utility for the RelatedSources extension. + * Wraps console methods with a consistent prefix. + */ +const logger = { + log: (...args) => console.log(PREFIX, ...args), + warn: (...args) => console.warn(PREFIX, ...args), + error: (...args) => console.error(PREFIX, ...args), +}; + +module.exports = { logger };