Skip to content

Commit 61bd19e

Browse files
committed
Initial commit
0 parents  commit 61bd19e

18 files changed

+2212
-0
lines changed

.eslintrc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"plugins": [
9+
"@typescript-eslint"
10+
],
11+
"rules": {
12+
"@typescript-eslint/naming-convention": "warn",
13+
"@typescript-eslint/semi": "warn",
14+
"curly": "warn",
15+
"eqeqeq": "warn",
16+
"no-throw-literal": "warn",
17+
"semi": "off"
18+
}
19+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
out
2+
node_modules
3+
.vscode-test/
4+
*.vsix

.vscodeignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
src/**
5+
.gitignore
6+
vsc-extension-quickstart.md
7+
**/tsconfig.json
8+
**/.eslintrc.json
9+
**/*.map
10+
**/*.ts

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to the "implicitparens" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
- Initial release

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Show Implicit Parentheses (JavaScript)
2+
3+
When reading complex expressions, it can be hard to understand how the subexpressions will be grouped. This extensions shows you how the sub expression are grouped by visually including the implicit parentheses as decorations.
4+
5+
## Command Pallet Commands
6+
7+
- "Show Implicit Parentheses"
8+
- "Hide Implicit Parentheses"
9+
- "Toggle Implicit Parentheses"
10+
11+
## Extension Settings
12+
13+
This extension contributes the following settings:
14+
15+
- `implicitparens.enabled`: enable/disable this extension
16+
17+
## TODO
18+
19+
- [ ] Ensure we can parse Flow and Typescript
20+
- [ ] Attempt to reparse on parser config change
21+
- [ ] Make config names human readable
22+
- [ ] Figure out how to configure colors
23+
- [ ] Set default color for light mode
24+
- [ ] Ensure plugin has name
25+
26+
## Possible Future Features
27+
28+
- Enable/disable menu bar item in config
29+
- Allow user to configure which parens are shown
30+
- Provide automated fixes for adding parens, or even extracting expressions to variables.

package.json

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"name": "implicitparens",
3+
"displayName": "ImplicitParens",
4+
"description": "Show implied parentheses in JavaScript code",
5+
"version": "0.0.1",
6+
"engines": {
7+
"vscode": "^1.48.0"
8+
},
9+
"categories": [
10+
"Other"
11+
],
12+
"activationEvents": [
13+
"onLanguage:typescript",
14+
"onLanguage:javascript",
15+
"onLanguage:javascriptreact",
16+
"onLanguage:typescriptreact"
17+
],
18+
"main": "./out/extension.js",
19+
"contributes": {
20+
"commands": [
21+
{
22+
"command": "implicitparens.toggleParens",
23+
"title": "Toggle Implicit Parentheses"
24+
},
25+
{
26+
"command": "implicitparens.showParens",
27+
"title": "Show Implicit Parentheses"
28+
},
29+
{
30+
"command": "implicitparens.hideParens",
31+
"title": "Hide Implicit Parentheses"
32+
}
33+
],
34+
"configuration": {
35+
"title": "Implicit Parentheses",
36+
"properties": {
37+
"implicitparens.enabled": {
38+
"type": "boolean",
39+
"default": true,
40+
"description": "Show implicit parentheses"
41+
},
42+
"implicitparens.parser": {
43+
"type": "string",
44+
"default": "TypeScript",
45+
"description": "Parser to use",
46+
"enum": [
47+
"JavaScript",
48+
"TypeScript",
49+
"Flow"
50+
],
51+
"enumDescriptions": [
52+
"Babel Parser",
53+
"Babel Parser with TypeScript enabled",
54+
"Babel Parser with Flow enabled"
55+
]
56+
}
57+
}
58+
},
59+
"colors": [
60+
{
61+
"id": "implicitparens.parens",
62+
"description": "Text color for the inserted parentheses",
63+
"defaults": {
64+
"dark": "#707070",
65+
"light": "#999999",
66+
"highContrast": "foreground"
67+
}
68+
}
69+
]
70+
},
71+
"scripts": {
72+
"vscode:prepublish": "yarn run compile",
73+
"compile": "tsc -p ./",
74+
"lint": "eslint src --ext ts",
75+
"watch": "tsc -watch -p ./",
76+
"pretest": "yarn run compile && yarn run lint",
77+
"test": "node ./out/test/runTest.js"
78+
},
79+
"devDependencies": {
80+
"@types/glob": "^7.1.3",
81+
"@types/mocha": "^8.0.0",
82+
"@types/node": "^14.0.27",
83+
"@types/vscode": "^1.48.0",
84+
"@typescript-eslint/eslint-plugin": "^3.8.0",
85+
"@typescript-eslint/parser": "^3.8.0",
86+
"eslint": "^7.6.0",
87+
"glob": "^7.1.6",
88+
"mocha": "^8.0.1",
89+
"typescript": "^3.8.3",
90+
"vscode-test": "^1.4.0"
91+
},
92+
"dependencies": {
93+
"@babel/parser": "^7.11.4",
94+
"@babel/traverse": "^7.11.0",
95+
"@types/babel__traverse": "^7.0.13",
96+
"@types/lodash": "^4.14.159",
97+
"lodash": "^4.17.20"
98+
},
99+
"prettier": {}
100+
}

src/commands.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
// The module 'vscode' contains the VS Code extensibility API
3+
// Import the module and reference it with the alias vscode in your code below
4+
import * as vscode from "vscode";
5+
import {
6+
ENABLED_CONFIG,
7+
SHOW_COMMAND,
8+
TOGGLE_COMMAND,
9+
HIDE_COMMAND,
10+
} from "./constants";
11+
12+
export function activateCommands(subscriptions: { dispose(): any }[]) {
13+
subscriptions.push(
14+
vscode.commands.registerCommand(SHOW_COMMAND, () => {
15+
vscode.workspace.getConfiguration().update(ENABLED_CONFIG, true);
16+
}),
17+
vscode.commands.registerCommand(HIDE_COMMAND, () => {
18+
vscode.workspace.getConfiguration().update(ENABLED_CONFIG, false);
19+
}),
20+
vscode.commands.registerCommand(TOGGLE_COMMAND, () => {
21+
const config = vscode.workspace.getConfiguration();
22+
// TODO: This technically returns a promise. If we got multiple toggles in
23+
// rapid succession, that's a race condition.
24+
config.update(
25+
ENABLED_CONFIG,
26+
!config.get(ENABLED_CONFIG),
27+
// TODO: Should this affect the workspace instead?
28+
true
29+
);
30+
})
31+
);
32+
}

src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const TOGGLE_COMMAND = "implicitparens.toggleParens";
2+
export const SHOW_COMMAND = "implicitparens.showParens";
3+
export const HIDE_COMMAND = "implicitparens.hideParens";
4+
5+
export const ENABLED_CONFIG = "implicitparens.enabled";
6+
export const PARSER_CONFIG = "implicitparens.parser";
7+
export const DEBOUNCE_TIME = 500;

src/extension.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
// The module 'vscode' contains the VS Code extensibility API
3+
// Import the module and reference it with the alias vscode in your code below
4+
import * as vscode from "vscode";
5+
import { activateParens } from "./parens";
6+
import { activateMenuBarItem } from "./menuBarItem";
7+
import { activateCommands } from "./commands";
8+
import { ENABLED_CONFIG } from "./constants";
9+
10+
// this method is called when vs code is activated
11+
export function activate(context: vscode.ExtensionContext) {
12+
activateMenuBarItem(context.subscriptions);
13+
activateCommands(context.subscriptions);
14+
15+
let parens: vscode.Disposable | null = null;
16+
function updateParensEnabled() {
17+
if (vscode.workspace.getConfiguration().get(ENABLED_CONFIG)) {
18+
if (parens === null) {
19+
parens = activateParens();
20+
} else {
21+
}
22+
} else {
23+
if (parens !== null) {
24+
parens.dispose();
25+
parens = null;
26+
} else {
27+
}
28+
}
29+
}
30+
31+
context.subscriptions.push(
32+
new vscode.Disposable(() => {
33+
if (parens !== null) {
34+
parens.dispose();
35+
}
36+
})
37+
);
38+
39+
updateParensEnabled();
40+
vscode.workspace.onDidChangeConfiguration(
41+
(event) => {
42+
if (event.affectsConfiguration(ENABLED_CONFIG)) {
43+
updateParensEnabled();
44+
}
45+
},
46+
null,
47+
context.subscriptions
48+
);
49+
}

src/menuBarItem.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from "vscode";
2+
import { ENABLED_CONFIG, TOGGLE_COMMAND } from "./constants";
3+
4+
export function activateMenuBarItem(subscriptions: { dispose(): any }[]) {
5+
const statusBarItem = vscode.window.createStatusBarItem(
6+
vscode.StatusBarAlignment.Left,
7+
100
8+
);
9+
10+
const PLAY = "\u25BA";
11+
const STOP = "\u25A0";
12+
13+
function setText() {
14+
const config = vscode.workspace.getConfiguration();
15+
const icon = config.get(ENABLED_CONFIG) ? STOP : PLAY;
16+
statusBarItem.text = `(${icon})`;
17+
}
18+
19+
setText();
20+
statusBarItem.show();
21+
statusBarItem.command = TOGGLE_COMMAND;
22+
23+
vscode.workspace.onDidChangeConfiguration(
24+
(event) => {
25+
if (event.affectsConfiguration(ENABLED_CONFIG)) {
26+
setText();
27+
}
28+
},
29+
null,
30+
subscriptions
31+
);
32+
subscriptions.push(statusBarItem);
33+
}

0 commit comments

Comments
 (0)