Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle the clj-kondo extension #426

Merged
merged 8 commits into from
Oct 25, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changes to Calva.

## [Unreleased]
- [Stop linting, start bundling clj-kondo](https://github.com/BetterThanTomorrow/calva/issues/423)

## [2.0.53] - 2019-10-24
- [Fix hang when user input is requested](https://github.com/BetterThanTomorrow/calva/issues/377)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Go to the [documentation](https://calva.readthedocs.io/) to find info on how to
- Ignore form (`#_`) dimming and `(comment)` form highlighting
- Code formatting and autoindent according to https://github.com/bbatsov/clojure-style-guide
- Structural Editing (via [Paredit](https://calva.readthedocs.io/en/latest/paredit.html))
- [Linting](https://calva.readthedocs.io/en/latest/linting.html)
- Intellisense
- Go to / Peek at definition
- View docstrings on hover
Expand Down
7 changes: 0 additions & 7 deletions docs/readthedocs/source/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,3 @@ The change would look like this in your `keybindings.json`:
"when": "editorHasSelection && editorTextFocus && !editorReadOnly && editorLangId =~ /clojure|scheme|lisp/ && paredit:keyMap =~ /original|strict/"
}
```

## Autolinting

The extension comes with autolinting disabled. This is because you will need to have [Joker](https://github.com/candid82/joker) installed in order for it to work. You will probably want to have Joker installed regardless so, just do it and then enable autolinting by setting:
```json
"calva.lintOnSave": true
```
3 changes: 2 additions & 1 deletion docs/readthedocs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Home

.. image:: https://raw.githubusercontent.com/BetterThanTomorrow/calva/dev/assets/calva-64h.png

`Calva <https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva>`_ is an integrated REPL powered environment for enjoyable and productive `Clojure <https://clojure.org>`_ and `ClojureScript <https://clojurescript.org>`_ in `Visual Studio Code <https://code.visualstudio.com>`_. It includes inline code evaluation, Paredit, code formatting, a test runner, syntax highlighting, and more. `Calva is open source <https://github.com/BetterThanTomorrow/calva>`_, and free to use.
`Calva <https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva>`_ is an integrated REPL powered environment for enjoyable and productive `Clojure <https://clojure.org>`_ and `ClojureScript <https://clojurescript.org>`_ in `Visual Studio Code <https://code.visualstudio.com>`_. It includes inline code evaluation, Paredit, code formatting, a test runner, syntax highlighting, `linting <linting.html>`_, and more. `Calva is open source <https://github.com/BetterThanTomorrow/calva>`_, and free to use.

Getting Started
---------------
Expand Down Expand Up @@ -36,6 +36,7 @@ I'm glad you asked! Please see the `Calva Development Wiki <https://github.com/B
connect-sequences
custom-commands
workspace-layouts
linting
rebl
vim
wsl
Expand Down
11 changes: 11 additions & 0 deletions docs/readthedocs/source/linting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Linting

Calva does no linting, yet with Calva you get excellent linting. That is because Calva bundles the [clj-kondo](https://marketplace.visualstudio.com/items?itemName=borkdude.clj-kondo) extension, which is powered by the [linter with the same name](https://github.com/borkdude/clj-kondo).

You might want to read about [how to configure clj-kondo](https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#configuration). These two sections might be of extra interest:
* [Exclude unresolved symbols from being reported](https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#exclude-unresolved-symbols-from-being-reported)
* [Lint a custom macro like a built-in macro](https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#lint-a-custom-macro-like-a-built-in-macro)

If you see clj-kondo squiggle the first character of the file with an error you don't quite understand, it is probably something wrong with your clj-kondo configuration.

The clj-kondo extension lints the current file as it is being edited. If you want to lint the whole project, use the clj-kondo cli command. See [https://github.com/borkdude/clj-kondo](https://github.com/borkdude/clj-kondo) for more info on that. Windows users might like to know that they too can get a clj-kondo cli command now, via [`npm install -g clj-kondo`](https://twitter.com/borkdude/status/1187622954236071936). It'll be a bit slower to start than the native build, but for sure it's better than not having a clj-kondo command! (Besides, the VS Code extension takes care of the cases where you really want speed.) See [https://github.com/borkdude/clj-kondo/blob/master/doc/install.md#npm-linux-macos-windows](https://github.com/borkdude/clj-kondo/blob/master/doc/install.md#npm-linux-macos-windows) for more on this.
19 changes: 5 additions & 14 deletions docs/readthedocs/source/quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ Here's a shocker for ya': Calva isn't perfect. 😄

There are quirks and things that flat out do not work. We'll try to collect info about such things here, providing workarounds when available (or, rather, known to us).

## Strange linting errors?

The Joker way of linting is awesome, but has its limitations. If you think the linting reporting is off, it is probably something you should check with the [Joker project](https://github.com/candid82/joker).

That said, this one might be worth a mention here:

### Unrecognized macros
One thing to note with this linter is that it doesn't do a full scan of all files and does not recognize macros it doesn't know about. Leading to false complaints about `Unable to resolve symbol x`. You might now and then tell it about macros you use. Create a `.joker` file somewhere in the path from the root of your project to where you are using the macro (the project root might be the best choice), and add:
```clojure
{:known-macros [some-ns/some-macro some-other-ns/some-other-macro]}
```
Read more about Joker's linter mode here: https://github.com/candid82/joker#linter-mode

## Test features not available with ClojureScript

Currently [`cider-nrepl` does not provide its test functionality for ClojureScript](https://github.com/clojure-emacs/cider-nrepl/issues/555) code. Please consider contributing to fixing that.
Expand All @@ -36,4 +23,8 @@ To make slurping and barfing forward really easy to perform they are bound to `c

## Calva and the VIM Extension

See [Using Calva with the VIM Extension](vim.md)
See [Using Calva with the VIM Extension](vim.md).

## Strange linting errors?

See [linting](linting.md).
2 changes: 1 addition & 1 deletion docs/readthedocs/source/wsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

If you want to use this extension with WSL, there are a few things that need to be configured first.

1. The `useWSL` option must be set to `true` (And if you are using the linter, you must add a valid WSL path to the `jokerPath` option.)
1. The `useWSL` option must be set to `true`
2. After doing the previous step, you must restart Visual Studio Code.
3. Make sure that you have Windows 10 version 1803 since that's the version that includes the `wslpath` tool which is used to convert between WSL and Windows paths.
4. If you're using Leiningen and if you want to view definitions of source files (e.g. `println`, `defn`, `def`) you will need to change your .m2 directory to a location directly accessible by Windows. For example, you could edit your `~/.lein/profiles.clj` like so:
Expand Down
8 changes: 4 additions & 4 deletions docs/things-to-do.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ The major themes are:

## The Right Features
* Support clj-fmt indent settings.
* Enable clj-kondo as default Calva linter ([clj-kondo](https://github.com/borkdude/clj-kondo/releases/tag/v2019.09.22-alpha) does support Windows but distributes no binary for Windows)
* [x] Enable clj-kondo as default Calva linter
* Enable using nrepl in streaming mode
* Use this for the test runner
* Add some basic refactorings support
* Add some basic refactoring support
* Use ”last opened in” column when opening the REPL window at jack in. (example? I do not fully understand.)
* Consider not opening the REPL window at jack-in / make it an option.
* Bettter connection life-cycle control fo shadow-cljs. Either:
1. Tap in to the shadow message bus (THeller said that there is such a thing that we can quyery about what shadow-cljs is doing.)
* Better connection life-cycle control fo shadow-cljs. Either:
1. Tap in to the shadow message bus (THeller said that there is such a thing that we can query about what shadow-cljs is doing.)
1. Run Jack-in in a Task proper and see if we can somehow catch the output. (This is needed for shadow-cljs Jack-in.)
* Consider supporting REBL out-of-the-box.
* Add more Calva extension context statuses and use it for more precise command and shortcut enablements.
Expand Down
24 changes: 4 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"workspaceContains:**/deps.edn"
],
"main": "./out/extension",
"extensionPack": [
"borkdude.clj-kondo"
],
"contributes": {
"languages": [
{
Expand Down Expand Up @@ -116,11 +119,6 @@
"default": false,
"description": "Run load-file when opening a new file and on file save"
},
"calva.lintOnSave": {
"type": "boolean",
"default": false,
"description": "Run joker-linting when opening a new file and on file save"
},
"calva.testOnSave": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -198,15 +196,10 @@
"connectedRegExp"
]
},
"calva.jokerPath": {
"type": "string",
"default": "joker",
"description": "Sets the path in which the Joker executable can be found. If useWSL has been set to true, this should be a valid WSL path."
},
"calva.useWSL": {
"type": "boolean",
"default": false,
"description": "Specifies if the nREPL and Joker are running within WSL."
"description": "Specifies if the nREPL is running within WSL."
},
"calva.jackInEnv": {
"type": "object",
Expand Down Expand Up @@ -667,11 +660,6 @@
"enablement": "calva:connected",
"category": "Calva"
},
{
"command": "calva.lintFile",
"title": "Lint Current File",
"category": "Calva"
},
{
"command": "calva.runNamespaceTests",
"title": "Run Tests for Current Namespace",
Expand Down Expand Up @@ -1039,10 +1027,6 @@
"command": "calva.requireREPLUtilities",
"key": "ctrl+alt+c ctrl+u"
},
{
"command": "calva.lintFile",
"key": "ctrl+alt+c l"
},
{
"command": "calva.runNamespaceTests",
"key": "ctrl+alt+c t"
Expand Down
16 changes: 2 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import TextDocumentContentProvider from './providers/content';
import HoverProvider from './providers/hover';
import { DefinitionProvider } from './providers/definition';
import EvaluateMiddleWare from './evaluate';
import LintMiddleWare from './lint';
import TestRunnerMiddleWare from './testRunner';
import annotations from './providers/annotations';
import select from './select';
Expand All @@ -27,7 +26,6 @@ import statusbar from './statusbar';
function onDidSave(document) {
let {
evaluate,
lint,
test
} = state.config();

Expand All @@ -44,20 +42,12 @@ function onDidSave(document) {
EvaluateMiddleWare.loadFile(document);
state.analytics().logEvent("Calva", "OnSaveLoad").send();
}
if (lint) {
LintMiddleWare.lintDocument(document);
state.analytics().logEvent("Calva", "OnSaveLint").send();
}
}

function onDidOpen(document) {
if (document.languageId !== 'clojure') {
return;
}

if (state.config().lint) {
LintMiddleWare.lintDocument(document);
}
}


Expand Down Expand Up @@ -111,7 +101,6 @@ function activate(context: vscode.ExtensionContext) {
replWindow.activate(context);

chan.appendLine("Calva activated.");
let { lint } = state.config();

status.update();

Expand All @@ -137,7 +126,6 @@ function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('calva.evaluateSelectionAsComment', EvaluateMiddleWare.evaluateSelectionAsComment));
context.subscriptions.push(vscode.commands.registerCommand('calva.evaluateTopLevelFormAsComment', EvaluateMiddleWare.evaluateTopLevelFormAsComment));
context.subscriptions.push(vscode.commands.registerCommand('calva.togglePrettyPrint', EvaluateMiddleWare.togglePrettyPrint));
context.subscriptions.push(vscode.commands.registerCommand('calva.lintFile', LintMiddleWare.lintDocument));
context.subscriptions.push(vscode.commands.registerCommand('calva.runTestUnderCursor', TestRunnerMiddleWare.runTestUnderCursorCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.runNamespaceTests', TestRunnerMiddleWare.runNamespaceTestsCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.runAllTests', TestRunnerMiddleWare.runAllTestsCommand));
Expand Down Expand Up @@ -199,7 +187,7 @@ function activate(context: vscode.ExtensionContext) {
const fileExtIfClj = editor.document.fileName.match(/\.clj[cs]?/);
if (fileExtIfClj && fileExtIfClj.length && state.config().syncReplNamespaceToCurrentFile) {
replWindow.setREPLNamespace(util.getDocumentNamespace(editor.document))
.catch(reasons => { console.warn(`Namespace sync failed, becauase: ${reasons}`) });
.catch(reasons => { console.warn(`Namespace sync failed, because: ${reasons}`) });
}
}
}));
Expand All @@ -215,7 +203,7 @@ function activate(context: vscode.ExtensionContext) {

vscode.commands.executeCommand('setContext', 'calva:activated', true);

greetings.activationGreetings(chan, lint);
greetings.activationGreetings(chan);

if (vimExtension) {
chan.appendLine(`VIM Extension detected. Please read: ${VIM_DOC_URL} now and then.\n`);
Expand Down
10 changes: 3 additions & 7 deletions src/greet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export function activationGreetings(chan, lintEnabled) {
export function activationGreetings(chan) {
chan.appendLine("Happy Clojure(script) coding! ❤️");
chan.appendLine("The Calva Team welcome you to the #calva-dev channel of the Clojurians Slack: https://clojurians.slack.com/messages/calva-dev/");
chan.appendLine("Please file any feature requests or bug reports here: https://github.com/BetterThanTomorrow/calva/issues");
chan.appendLine("I will also respond to any @pez mentions in the #calva-dev channel of the Clojurians Slack: https://clojurians.slack.com/messages/calva-dev/");
chan.appendLine("");
if (!lintEnabled) {
chan.appendLine("")
chan.appendLine("NOTE: Autolinting is disabled. You need to enable \"calva.lintOnSave\" in your editor settings to use it. But first install Joker: https://github.com/candid82/joker");
}
chan.appendLine("NOTE: Calva bundles the clj-kondo extension for your linting needs. Please see: https://calva.readthedocs.io/en/latest/linting.html");
chan.appendLine("--");
}
100 changes: 0 additions & 100 deletions src/lint.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ function config() {
return {
format: configOptions.get("formatOnSave"),
evaluate: configOptions.get("evalOnSave"),
lint: configOptions.get("lintOnSave"),
test: configOptions.get("testOnSave"),
jokerPath: configOptions.get("jokerPath"),
useWSL: configOptions.get("useWSL"),
syncReplNamespaceToCurrentFile: configOptions.get("syncReplNamespaceToCurrentFile"),
jackInEnv: configOptions.get("jackInEnv"),
Expand Down