Skip to content

Commit

Permalink
Merge pull request #362 from BetterThanTomorrow/wip/clojure-warrior-i…
Browse files Browse the repository at this point in the history
…nline

Move Clojure Warrior into Calva
  • Loading branch information
PEZ authored Oct 1, 2019
2 parents b9d8acc + 100696e commit 432d98a
Show file tree
Hide file tree
Showing 13 changed files with 702 additions and 17 deletions.
22 changes: 21 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
"--extensionDevelopmentPath=${workspaceRoot}",
],
"stopOnEntry": false,
"sourceMaps": true,
"env": {
"CALVA_DEV_GA": "FUBAR-69796730-4",
"DEBUG": "no-debug-universal-analytics"
},
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
},
{
"name": "Launch w/ test folder",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"${workspaceFolder}/test-data"
],
"stopOnEntry": false,
"sourceMaps": true,
Expand All @@ -22,5 +41,6 @@
"${workspaceFolder}/dist/**/*.js"
]
}

]
}
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Changes to Calva.
## When time allows, this will be worked on
- [Support for custom project/workflow commands](https://github.com/BetterThanTomorrow/calva/issues/281)

## Being distilled

## [Unreleased]
- [Insourcing @tonsky's Clojue Warrior, now named Calva Highlight](https://github.com/BetterThanTomorrow/calva/pull/362)
- [Update status bar when configuration changed](https://github.com/BetterThanTomorrow/calva/issues/358)

## [2.0.42] - 29.09.2019
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ When something doesn't work and you think there might be a workaround for it, pl
## Features

### At a glance
- Syntax highlighting, plus:
- Rainbow parens
- Highlights misplaced brackets
- LISP friendly bracket matching
- Ignore form (`#_`) dimming and `(comment)` form highlighting
- Clojure code formatting
- Quickly and easily get your REPL connected
- Evaluate code inline
- Run tests
Expand Down Expand Up @@ -112,19 +118,27 @@ To make slurping and barfing forward really easy to perform they are bound to `c

![Disable Mission Control Shortcuts](/assets/mission-control-shortcuts.gif)

### Conflicting with Parinfer extension
## Calva Highlight

There have been reports of the Parinfer extension and Calva not working too well together. You might to some extent get away with switching off Calva's formatting as-you-type, but also you might not. With Calva it is probably better to learn to use Paredit **slurp** and **barf** and generally rely on Calva's automatic formatting.
Calva takes care of syntax highlighting, and also provides some features not available through VS Code's highlighting mechanism. These extras inclode rainbow parens, sane bracket matching, and comment form dimming/highlighting.

You are in charge of how brackets and comments are highlighted:

## Clojure Warrior included
| Setting | Meaning | Example |
| --- | ------- | ------- |
| `"calva.highlight.enableBracketColors"` | Enable rainbow colors | `true` |
| `"calva.highlight.bracketColors"` | Which colors to use | `["#000", "#999"]` |
| `"calva.highlight.cycleBracketColors"` | Whether same colors should be reused for deeply nested brackets | `true` |
| `"calva.highlight.misplacedBracketStyle"` | Style of misplaced bracket | `{ "border": "2px solid #c33" }` |
| `"calva.highlight.matchedBracketStyle"` | Style of bracket pair highlight | `{"backgroundColor": "#E0E0E0"}` |
| `"calva.highlight.ignoredFormStyle"` | Style of `#_...` form | `{"textDecoration": "none; opacity: 0.5"}` |
| `"calva.highlight.commentFormStyle"` | Style of `(comment ...)` form | `{"fontStyle": "italic"}` |

This extension bundles [@tonsky](https://tonsky.me)'s [Clojure Warrior](https://marketplace.visualstudio.com/items?itemName=tonsky.clojure-warrior). Bringing you, amongst other things, rainbow parens and sane bracket matching.
Calva Highlight is built from **Clojure Warrior**, created by [Nikita Prokopov, a.k.a. @tonsky](https://tonsky.me)'s.

Note: If you for some reason do not want rainbow colors, put this in your `settings.json`:
## Conflicting with Parinfer extension

```json
"clojureWarrior.enableBracketColors": false
```
There have been reports of the Parinfer extension and Calva not working too well together. You might to some extent get away with switching off Calva's formatting as-you-type, but also you might not. With Calva it is probably better to learn to use Paredit **slurp** and **barf** and generally rely on Calva's automatic formatting.

## How to contribute

Expand All @@ -136,7 +150,7 @@ Calva is built using a combination of TypeScript and ClojureScript. The ClojureS

Many people have contributed to Calva. Here are the ones who have engaged in the project as such.

## Current Maintainers:
### Current Maintainers:

* [Peter Strömberg](https://github.com/PEZ)
* [Kevin Stehn](https://github.com/kstehn)
Expand Down
Binary file added assets/cw_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions calva/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import * as paredit from "./paredit/extension";
import * as fmt from "./calva-fmt/ts/extension";
import * as highlight from "./highlight/src/extension";
import * as state from './state';
import * as jackIn from './nrepl/jack-in';
import * as util from './utilities'
Expand Down Expand Up @@ -69,6 +70,8 @@ function activate(context: vscode.ExtensionContext) {
const legacyExtension = vscode.extensions.getExtension('cospaia.clojure4vscode'),
fmtExtension = vscode.extensions.getExtension('cospaia.calva-fmt'),
pareEditExtension = vscode.extensions.getExtension('cospaia.paredit-revived'),
cwExtension = vscode.extensions.getExtension('tonsky.clojure-warrior'),
cwConfig = vscode.workspace.getConfiguration('clojureWarrior'),
customCljsRepl = state.config().customCljsRepl,
replConnectSequences = state.config().replConnectSequences,
BUTTON_GOTO_WIKI = "Open the Wiki",
Expand Down Expand Up @@ -216,6 +219,19 @@ function activate(context: vscode.ExtensionContext) {
chan.appendLine("Default keybinding for Jack-in: ctrl+alt+c ctrl+alt+j");
state.analytics().logPath("/activated").logEvent("LifeCycle", "Activated").send();

if (!cwExtension) {
highlight.activate(context);
} else {
vscode.window.showErrorMessage("Clojure Warrior extension detected. Please uninstall it before continuing to use Calva.", ...["Got it.","Will do!"]);
}

for (const config of ["enableBracketColors", "bracketColors", "cycleBracketColors", "misplacedBracketStyle", "matchedBracketStyle", "commentFormStyle", "ignoredFormStyle"]) {
if (cwConfig.get(config) !== undefined) {
vscode.window.showWarningMessage("Legacy Clojure Warrior settings detected. These settings have changed prefix/namespace to from `clojureWarrior´ to `calva.highlight`. You should update `settings.json`.", ...["Roger that!"]);
break;
}
}

return {
hasParedit: true,
hasFormatter: true
Expand Down
70 changes: 70 additions & 0 deletions calva/highlight/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 0.2.4 - July 12, 2019

- Fixed trailing whitespace in comment, symbols with word comment in them (#15, #17)

# 0.2.3 - July 10, 2019

- Do not merge defaults for `commentFormStyle` and `ignoredFormStyle`

# 0.2.2 - July 10, 2019

- Comment decoration (#14 by @PEZ)

# 0.2.1 - July 4, 2019

- Removed `configurationDefault` as it was conflicting with Calva (#13)

# 0.2.0

- Option to disable rainbow brackets `clojureWarrior.enableBracketColors` (#12)
- Handle setting `clojureWarrior.bracketColors` to empty array (#12)
- Handle config changes when done from Setting GUI
- Disable default `editor.matchBrackets` for Clojure files

# 0.1.8

- Highlight and match compound brackets: `#()`, `#{}`, `#?()`, `#?@()` (#10, thx @maratynsky)

# 0.1.7

- Show mismatched brackets on scrollbar (#7, #8)

# 0.1.6

- Avoid bracket styles bleeding into text typed next to them

# 0.1.5

- Don’t show matched brackets inside selection (#4)
- Do not alter `editor.matchBrackets` in config dynamically (#3)
- Showing matching bracket immediately since it’s fast (#5)
- Jump to match should scroll if needed (#2)

# 0.1.4

- More distinct rainbow colors by default
- Default settings support both dark and light themes

# 0.1.3

- New command: `clojureWarrior.jumpToMatchingBracket`
- New command: `clojureWarrior.selectToMatchingBracket`
- `editor.matchBrackets` is set to false only for Clojure editors
- `matchPairs` is scheduled asynchronously not to slow down text editing

# 0.1.2

- Highlight bracket pairs
- Added config param: `"clojureWarrior.matchedBracketStyle": {"backgroundColor": "#E0E0E0"}`

# 0.1.1

Added configuration parameters:
- `"clojureWarrior.bracketColors": ["#000", "#999", ...]`
- `"clojureWarrior.cycleBracketColors": true`
- `"clojureWarrior.misplacedBracketStyle": { "border": "2px solid #c33" }`

# 0.1.0

- Initial release
- Rainbow Brackets
21 changes: 21 additions & 0 deletions calva/highlight/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Nikita Prokopov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
81 changes: 81 additions & 0 deletions calva/highlight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Clojure Warrior

<img src="https://raw.githubusercontent.com/tonsky/clojure-warrior/master/extras/icon.png" width="128px" height="128px">

Visual Studio Code extension for Clojure development

## Features

Rainbow brackets:

- Chooses bracket color based on nesting level
- Distinct bracket colors, plays well with [Alabaster theme](https://marketplace.visualstudio.com/items?itemName=tonsky.theme-alabaster)
- Properly handles strings, comments and escaped characters
- Highlights misplaced brackets

Bracket pair matching:

- Higlights corresponding bracket pair to the one under the cursor
- Considers bracket directon and cursor position relative to it
- Only highlights pair when cursor is standing _outside_ the expression (right after the closed bracket or right before opening one)

Jump to matching bracket commands:

- Jump to corresponding bracket pair (same rules as in bracket pair matching): `clojureWarrior.jumpToMatchingBracket`
- Select a region between cursor and matching bracket (including brackets): `clojureWarrior.selectToMatchingBracket`

![Screenshot](https://raw.githubusercontent.com/tonsky/clojure-warrior/master/extras/screenshot.png)

## Configuration

| Key | Meaning | Example |
| --- | ------- | ------- |
| `"clojureWarrior.enableBracketColors"` | Enable rainbow colors | `true` |
| `"clojureWarrior.bracketColors"` | Which colors to use | `["#000", "#999"]` |
| `"clojureWarrior.cycleBracketColors"` | Whether same colors should be reused for deeply nested brackets | `true` |
| `"clojureWarrior.misplacedBracketStyle"` | Style of misplaced bracket | `{ "border": "2px solid #c33" }` |
| `"clojureWarrior.matchedBracketStyle"` | Style of bracket pair highlight | `{"backgroundColor": "#E0E0E0"}` |
| `"clojureWarrior.commentFormStyle"` | Style of `(comment ...)` form | `{"textDecoration": "none; opacity: 0.5"}` |
| `"clojureWarrior.ignoredFormStyle"` | Style of `#_...` form | `{"textDecoration": "none; opacity: 0.5"}` |

To disable VS Code default bracket matching for Clojure files, add this to `settings.json`:

```
"[clojure]": {
"editor.matchBrackets": false
}
```

## Installation

1. Go to `Extensions`
2. Search for `Clojure Warrior`
3. Install
4. Restart Visual Studio Code (or click `Reload window`)
5. Open a Clojure/ClojureScript/EDN file

## Workign on Clojure Warrior

Compiling:

```
cd clojure-warrior
npm install
npm run watch
```

Installing dev version locally:

```
ln -s `pwd` ~/.vscode/extensions/tonsky.clojure-warrior-0.2.0
```

Publishing:

```
vsce publish
```

## License

[MIT License](https://github.com/tonsky/clojure-warrior/blob/master/./LICENSE.txt)
Loading

0 comments on commit 432d98a

Please sign in to comment.