Skip to content

Commit 0a2924a

Browse files
authored
Merge pull request #14 from dandehoon/feat/per-lang-config
feat: add per-language defined config
2 parents e209148 + 9002516 commit 0a2924a

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"outFiles": [
1212
"${workspaceFolder}/out/**/*.js"
1313
],
14-
"preLaunchTask": "${workspaceFolder}/npm: watch"
14+
"preLaunchTask": "pnpm: watch"
1515
},
1616
{
1717
"name": "Extension Tests",
@@ -24,7 +24,7 @@
2424
"outFiles": [
2525
"${workspaceFolder}/out/test/**/*.js"
2626
],
27-
"preLaunchTask": "npm: watch"
27+
"preLaunchTask": "pnpm: watch"
2828
}
2929
]
3030
}

.vscode/tasks.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"type": "npm",
6-
"script": "watch",
7-
"problemMatcher": "$tsc-watch",
5+
"label": "pnpm: watch",
6+
"type": "shell",
7+
"command": "pnpm watch",
88
"isBackground": true,
99
"presentation": {
1010
"reveal": "never"
1111
},
1212
"group": {
1313
"kind": "build",
1414
"isDefault": true
15-
}
15+
},
16+
"problemMatcher": "$tsc-watch"
1617
}
1718
]
1819
}

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ With cursor on `xamp`, next expansions will be:
4040
→ const config = { url: 'https://example.com' };
4141
```
4242

43+
## Configuration
44+
45+
Customize token expansion by adding `genericExpandSelection.token.patterns` to your `settings.json`. This setting takes an array of regex strings, which are tried in order. You can set a global default and override it for specific languages.
46+
47+
```jsonc
48+
{
49+
// Global setting for all languages
50+
"genericExpandSelection.token.patterns": [
51+
"[a-zA-Z0-9_-]+", // matches alphanumeric characters, underscores, and hyphens
52+
"[a-zA-Z0-9_\\-.]+", // matches identifiers with dots
53+
"[^\\s[\\]{}()\"'`]+" // matches any non-whitespace, non-bracket character
54+
],
55+
56+
// Override for a specific language (e.g., TypeScript)
57+
"[typescript]": {
58+
"genericExpandSelection.token.patterns": [
59+
"\\w+" // In TypeScript, only match word characters
60+
]
61+
}
62+
}
63+
```
64+
4365
## Commands
4466

4567
- **`genericExpandSelection.expand`**: Expand Selection
@@ -57,11 +79,14 @@ pnpm run check
5779
# Run tests (builds TypeScript, runs esbuild, then executes tests)
5880
pnpm run test
5981

82+
# Watch for changes and rebuild
83+
pnpm run watch
84+
6085
# Build, type check, lint, and package extension as out.vsix
6186
pnpm run build
6287

6388
# Build and install the packaged extension locally (outputs out.vsix and installs it)
64-
pnpm run vsce:install
89+
pnpm run local
6590
```
6691

6792
## License

esbuild.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ const esbuildProblemMatcherPlugin = {
4040
});
4141
build.onEnd((result) => {
4242
result.errors.forEach(({ text, location }) => {
43-
console.error(`✘ [ERROR] ${text}`);
4443
console.error(
45-
` ${location.file}:${location.line}:${location.column}:`,
44+
`${location.file}:${location.line}:${location.column}: error: ${text}`,
4645
);
4746
});
4847
console.log('[watch] build finished');

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@
5757
"[a-zA-Z0-9_\\-.#$@%]+",
5858
"[^\\s[\\]{}()\"'`]+"
5959
],
60-
"description": "Regular expressions for token pattern matching during selection expansion"
60+
"description": "Regular expressions for token pattern matching during selection expansion",
61+
"scope": "language-overridable"
6162
}
6263
}
6364
}
6465
},
6566
"scripts": {
6667
"check": "tsc --noEmit && eslint src --ext ts",
6768
"test": "tsc -p . --outDir out && node esbuild.js && vscode-test",
69+
"watch": "node esbuild.js --watch",
6870
"build": "pnpm run check && node esbuild.js --production && pnpm dlx vsce package --no-dependencies -o out.vsix",
6971
"publish": "pnpm dlx vsce publish --no-dependencies",
7072
"local": "pnpm run build && code --install-extension out.vsix"

src/finders/token.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export function findToken(
2121
const currentPosition = document.positionAt(startIndex);
2222

2323
// Get user-configured patterns or use defaults
24-
const config = vscode.workspace.getConfiguration('genericExpandSelection');
24+
const config = vscode.workspace.getConfiguration(
25+
'genericExpandSelection',
26+
document,
27+
);
2528
const userPatterns: string[] = config.get('token.patterns', [
2629
'[a-zA-Z0-9_-]+',
2730
'[a-zA-Z0-9_\\-.]+',

0 commit comments

Comments
 (0)