Skip to content

Commit

Permalink
Merge pull request #944 from BetterThanTomorrow/use_clj-kondo_through…
Browse files Browse the repository at this point in the history
…_clojure-lsp

Use clj kondo through clojure lsp
  • Loading branch information
bpringe authored Jan 13, 2021
2 parents ad47f48 + 68507a9 commit 8a0f2c9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ tasks:
# command: clojure -Sdeps '{:deps {nrepl {:mvn/version "0.6.0"} cider/cider-nrepl {:mvn/version "0.23.0"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
vscode:
extensions:
- [email protected]:QqaT9WwNey/mBcvg2i0WUA==
- [email protected]:yW4qKh9L7nu9rnAAEWf7Jw==
- [email protected]:QqaT9WwNey/mBcvg2i0WUA==
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Changes to Calva.

## [Unreleased]
- [Stop bundling clj-kondo in favor of using it through clojure-lsp](https://github.com/BetterThanTomorrow/calva/issues/868)

## [2.0.149] - 2021-01-12
- Fix: [calva.jackInEnv does not resolve `${env:...}`](https://github.com/BetterThanTomorrow/calva/issues/933)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Welcome to [Calva](https://marketplace.visualstudio.com/items?itemName=bettertha
## Users Like it 😍

Crispin Bennett's review:
> This is great, and makes VS Code a truly viable IDE/editor for clojure development. It has great REPL support (including inline evaluation), an extensive Paredit implementation, and excellent linting (care of the bundled clj-kondo). Calva is being improved on at an impressive clip by maintainers who appear solidly committed to its ongoing development. It's well-documented, and manages to be both approachable and capable. A no-brainer if you're already a VS Code user, and well worth a look if you're not.
> This is great, and makes VS Code a truly viable IDE/editor for clojure development. It has great REPL support (including inline evaluation), an extensive Paredit implementation, and excellent linting (thanks to clojure-lsp and clj-kondo). Calva is being improved on at an impressive clip by maintainers who appear solidly committed to its ongoing development. It's well-documented, and manages to be both approachable and capable. A no-brainer if you're already a VS Code user, and well worth a look if you're not.
## There is Documentation

Expand Down
6 changes: 3 additions & 3 deletions docs/site/linting.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 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).
Calva does no linting, yet with Calva you get excellent linting. That is because Calva uses [clojure-lsp](https://github.com/clojure-lsp/clojure-lsp), which provides linting powered by 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.
If you see a linting squiggle under 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.
Files are linted as they're 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! 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.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
"onDebugResolve:type"
],
"main": "./out/extension",
"extensionPack": [
"borkdude.clj-kondo"
],
"contributes": {
"debuggers": [
{
Expand Down Expand Up @@ -263,7 +260,7 @@
},
"clj-kondo": {
"type": "string",
"description": "This clj-kondo instance is used by the Calva debugger. (Not to be confused with the clj-kondo used by the extension with the same name that gives you linting.)"
"description": "This clj-kondo is used by the Calva debugger for finding usages, not for linting."
}
},
"default": {
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function activate(context: vscode.ExtensionContext) {
const pareEditExtension = vscode.extensions.getExtension('cospaia.paredit-revived');
const cwExtension = vscode.extensions.getExtension('tonsky.clojure-warrior');
const vimExtension = vscode.extensions.getExtension('vscodevim.vim');
const cljKondoExtension = vscode.extensions.getExtension('borkdude.clj-kondo');
const cwConfig = vscode.workspace.getConfiguration('clojureWarrior');
const customCljsRepl = state.config().customCljsRepl;
const replConnectSequences = state.config().replConnectSequences;
Expand Down Expand Up @@ -106,6 +107,10 @@ function activate(context: vscode.ExtensionContext) {

state.setExtensionContext(context);

if (cljKondoExtension) {
vscode.window.showWarningMessage("The clj-kondo extension is detected. You will see duplicate linting reports in some cases. Please uninstall the clj-kondo extension.", "Got it!");
}

if (!fmtExtension) {
try {
fmt.activate(context);
Expand Down
16 changes: 8 additions & 8 deletions src/lsp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as vscode from 'vscode';
import { LanguageClient, RequestType, ServerOptions, LanguageClientOptions } from 'vscode-languageclient';
import { LanguageClient, ServerOptions, LanguageClientOptions } from 'vscode-languageclient';
import * as path from 'path';
import * as state from './state';
import * as util from './utilities'
import config from './config';
import { provideClojureDefinition } from './providers/definition';

function createClient(jarPath: string): LanguageClient {
Expand All @@ -23,12 +24,15 @@ function createClient(jarPath: string): LanguageClient {
"document-formatting?": false,
"document-range-formatting?": false,
"keep-require-at-start?": true,
//"use-metadata-for-privacy?": false
},
middleware: {
handleDiagnostics(uri, diagnostics, next) {
if (uri.path.endsWith(config.REPL_FILE_EXT)) {
return;
}
return next(uri, diagnostics);
},
provideCodeActions(document, range, context, token, next) {
// Disable code actions
//return [];
return next(document, range, context, token);
},
provideCodeLenses: async (document, token, next): Promise<vscode.CodeLens[]> => {
Expand All @@ -43,10 +47,6 @@ function createClient(jarPath: string): LanguageClient {
}
return null;
},
handleDiagnostics(uri, diagnostics, next) {
// Disable diagnostics from clojure-lsp
return;
},
provideHover(document, position, token, next) {
if (util.getConnectedState()) {
return null;
Expand Down
5 changes: 0 additions & 5 deletions src/results-output/results-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ export function setContextForOutputWindowActive(isActive: boolean): void {
}

export async function initResultsDoc(): Promise<vscode.TextDocument> {
// await state.initProjectDir();
const kondoPath = vscode.Uri.joinPath(OUTPUT_FILE_DIR(), '.clj-kondo');
await vscode.workspace.fs.createDirectory(kondoPath);
await writeTextToFile(vscode.Uri.joinPath(kondoPath, 'config.edn'), "^:replace {:linters {}}");

await vscode.workspace.fs.createDirectory(OUTPUT_FILE_DIR());
let resultsDoc: vscode.TextDocument;
try {
Expand Down

0 comments on commit 8a0f2c9

Please sign in to comment.