Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is example gh opened issue


- 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:
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 4 additions & 4 deletions src/extension.js
Original file line number Diff line number Diff line change
@@ -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!');
Expand Down Expand Up @@ -209,6 +208,7 @@ class RelatedSources {

const config = vscode.workspace.getConfiguration('relatedsources');
const matchers = config.matchers || [];
const slowMatcherThresholdMs = config.get('slowMatcherThresholdMs', 1000);

let candidateUris = [];

Expand Down Expand Up @@ -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. ` +
Expand Down
15 changes: 15 additions & 0 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -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 };