Skip to content

Commit

Permalink
Merge branch dev into published
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Nov 3, 2022
2 parents 79557eb + cfc1193 commit b526450
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ backup/
# Calva grammars (running the atom-ci docker image locally)
src/calva-fmt/atom-language-clojure/.cache/
src/calva-fmt/atom-language-clojure/.bash_history

# Leiningen
.lein-repl-history
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Changes to Calva.

## [Unreleased]

## [2.0.315] - 2022-11-03

- [Inform if Calva nREPL dependencies are not fulfilled](https://github.com/BetterThanTomorrow/calva/issues/1935)
- Fix: [Calva does not fall back on lsp definitions when nrepl definitions fail](https://github.com/BetterThanTomorrow/calva/issues/1933)
- Fix: [Warnings printed with an added `;` on a line of its own](https://github.com/BetterThanTomorrow/calva/issues/1930)
- Fix: [Extra newlines are printed in output from function called from test](https://github.com/BetterThanTomorrow/calva/issues/1937)

## [2.0.314] - 2022-11-01

- [Squash spaces when Paredit Kill/Delete Right](https://github.com/BetterThanTomorrow/calva/issues/1923)
Expand Down
4 changes: 3 additions & 1 deletion docs/site/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ search:

# Connect Calva to Your Project

The recommended way is to:
When connected to your project's REPL Calva let's you evaluate code, supporting Interactive Programming. The REPL connection is also used to provide IDE functionality through the dynamic knowledge about the project that the REPL enables. The REPL communication depends on that your project has an [nREPL](https://github.com/nrepl/nrepl) server running, and that the [cider-nrepl](https://github.com/clojure-emacs/cider-nrepl) middleware is enabled.

For the easiest way to provide your project with these dependencies, the recommended way to connect is to use the so called **Jack-in** command.

## Jack-in: Let Calva Start the REPL For You

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Calva: Clojure & ClojureScript Interactive Programming",
"description": "Integrated REPL, formatter, Paredit, and more. Powered by cider-nrepl and clojure-lsp.",
"icon": "assets/calva.png",
"version": "2.0.314",
"version": "2.0.315",
"publisher": "betterthantomorrow",
"author": {
"name": "Better Than Tomorrow",
Expand Down
24 changes: 21 additions & 3 deletions src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { disabledPrettyPrinter } from './printer';
import { keywordize } from './util/string';
import { initializeDebugger } from './debugger/calva-debug';
import * as outputWindow from './results-output/results-doc';
import { formatAsLineComments } from './results-output/util';
import { evaluateInOutputWindow } from './evaluate';
import * as liveShareSupport from './live-share';
import * as calvaDebug from './debugger/calva-debug';
Expand Down Expand Up @@ -103,7 +104,9 @@ async function connectToHost(hostname: string, port: number, connectSequence: Re
setStateValue('clj', cljSession);
setStateValue('cljc', cljSession);
status.update();
outputWindow.appendLine(`; Connected session: clj\n${outputWindow.CLJ_CONNECT_GREETINGS}`);
outputWindow.appendLine(
`; Connected session: clj\n${formatAsLineComments(outputWindow.CLJ_CONNECT_GREETINGS)}`
);
replSession.updateReplSessionType();

initializeDebugger(cljSession);
Expand Down Expand Up @@ -179,9 +182,9 @@ function setUpCljsRepl(session, build) {
setStateValue('cljs', session);
status.update();
outputWindow.appendLine(
`; Connected session: cljs${build ? ', repl: ' + build : ''}\n${
`; Connected session: cljs${build ? ', repl: ' + build : ''}\n${formatAsLineComments(
outputWindow.CLJS_CONNECT_GREETINGS
}`
)}`
);
outputWindow.setSession(session, 'cljs.user');
replSession.updateReplSessionType();
Expand Down Expand Up @@ -631,6 +634,21 @@ export async function connect(
} catch (e) {
console.error(e);
}
if (!['babashka', 'nbb', 'joyride', 'generic'].includes(connectSequence.projectType)) {
await nClient.session.info('clojure.core', 'map').catch((e) => {
void vscode.window
.showWarningMessage(
"Calva failed to perform a basic nREPL 'info' call. You need to start the REPL with cider-nrepl dependencies met",
'Show Calva Connect Docs'
)
.then((choice) => {
if (choice === 'Show Calva Connect Docs') {
void vscode.commands.executeCommand('simpleBrowser.show', 'https://calva.io/connect/');
}
});
console.error(`cider-nrepl dependencies not met: `, e);
});
}
return true;
}

Expand Down
16 changes: 4 additions & 12 deletions src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function evaluateCodeUpdatingUI(
});
// May need to move this inside of onResultsAppended callback above, depending on desired ordering of appended results
if (err.length > 0) {
const errMsg = `; ${asLineCommentAndJoin(err)}`;
const errMsg = formatAsLineComments(err.join('\n'));
if (context.stacktrace) {
outputWindow.saveStacktrace(context.stacktrace);
outputWindow.appendLine(errMsg, (_, afterResultLocation) => {
Expand All @@ -163,7 +163,7 @@ async function evaluateCodeUpdatingUI(
} catch (e) {
if (showErrorMessage) {
const outputWindowError = err.length
? `; ${asLineCommentAndJoin(err)}`
? formatAsLineComments(err.join('\n'))
: formatAsLineComments(e);
outputWindow.appendLine(outputWindowError, async (resultLocation, afterResultLocation) => {
if (selection) {
Expand Down Expand Up @@ -261,14 +261,6 @@ function printWarningForError(e: any) {
console.warn(`Unhandled error: ${e.message}`);
}

function asLineComment(str: string): string {
return str.replace(/\n\r?/, '\n; ');
}

function asLineCommentAndJoin(strings: string[]): string {
return strings.map((s) => asLineComment(s)).join('\n; ');
}

function _currentSelectionElseCurrentForm(editor: vscode.TextEditor): getText.SelectionAndText {
if (editor.selection.isEmpty) {
return getText.currentFormText(editor?.document, editor.selection.active);
Expand Down Expand Up @@ -434,8 +426,8 @@ async function loadFile(
filePath: docUri.path,
stdout: (m) => outputWindow.append(m),
stderr: (m) => {
outputWindow.appendLine('; ' + asLineComment(m));
errorMessages.push(asLineComment(m));
outputWindow.appendLine(formatAsLineComments(m));
errorMessages.push(m);
},
pprintOptions: pprintOptions,
});
Expand Down
6 changes: 3 additions & 3 deletions src/extension-test/unit/results-output/util-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('addToHistory', () => {
});
it('should push text to history array without whitespace or eol characters', () => {
const history = [];
const newHistory = util.addToHistory(history, ' \t\nhello \n\r');
const newHistory = util.addToHistory(history, ' \t\nhello \r\n');
expect(newHistory[0]).toBe('hello');
});
it('should not push text to history array if empty string', () => {
Expand All @@ -36,8 +36,8 @@ describe('formatAsLineComments', () => {
const formattedError = util.formatAsLineComments(error);
expect(formattedError).toBe('; hello\n; world');
});
it('should account for \\n\\r line endings', () => {
const error = 'hello\n\rworld\n\r';
it('should account for \\r\\n line endings', () => {
const error = 'hello\r\nworld\r\n';
const formattedError = util.formatAsLineComments(error);
expect(formattedError).toBe('; hello\n; world');
});
Expand Down
8 changes: 0 additions & 8 deletions src/nrepl/cider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ function resultMessage(resultItem: Readonly<TestResult>): string {
return `${msg.length > 0 ? stripTrailingNewlines(msg.join(': ')) : ''}`;
}

// Remove any trailing blank lines from any of the string in result.
export function cleanUpWhiteSpace(result: TestResult) {
for (const prop in result) {
if (typeof result[prop] === 'string') {
result[prop] = stripTrailingNewlines(result[prop]);
}
}
}
// Given a summary, return a message suitable for printing in the REPL to show
// the user a quick summary of the test run.
// Examples:
Expand Down
2 changes: 1 addition & 1 deletion src/nrepl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class NReplSession {

if ((msgData.out || msgData.err) && this.replType) {
if (msgData.out) {
outputWindow.appendLine(msgData.out);
outputWindow.append(msgData.out);
} else if (msgData.err) {
const err = formatAsLineComments(msgData.err);
outputWindow.appendLine(err, (_) => {
Expand Down
11 changes: 10 additions & 1 deletion src/providers/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ export class ClojureDefinitionProvider implements vscode.DefinitionProvider {
for (const provider of providers) {
const providerFunction = definitionFunctions[provider];
if (providerFunction) {
const definition = await providerFunction(document, position, token);
const definition = await providerFunction(document, position, token).catch((e) => {
console.error(
`Definition lookup failed for provider '${provider}', ${
provider === 'lsp'
? 'is clojure-lsp running and configured correctly?'
: 'do you have the cider-nrepl dependency loaded in your project? See https://calva.io/connect'
}`,
e
);
});
if (definition) {
if (definition instanceof vscode.Location) {
return definition;
Expand Down
53 changes: 28 additions & 25 deletions src/results-output/results-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@ import * as replHistory from './repl-history';
import * as docMirror from '../doc-mirror/index';
import { PrintStackTraceCodelensProvider } from '../providers/codelense';
import * as replSession from '../nrepl/repl-session';
import { splitEditQueueForTextBatching } from './util';
import { formatAsLineComments, splitEditQueueForTextBatching } from './util';

const RESULTS_DOC_NAME = `output.${config.REPL_FILE_EXT}`;

const PROMPT_HINT = '; Use `alt+enter` to evaluate';

const START_GREETINGS =
'; This is the Calva evaluation results output window.\n\
; TIPS: The keyboard shortcut `ctrl+alt+o o` shows and focuses this window\n\
; when connected to a REPL session.\n\
; Please see https://calva.io/output/ for more info.\n\
; Happy coding! ♥️';

export const CLJ_CONNECT_GREETINGS =
'; TIPS:\n\
; - You can edit the contents here. Use it as a REPL if you like.\n\
; - `alt+enter` evaluates the current top level form.\n\
; - `ctrl+enter` evaluates the current form.\n\
; - `alt+up` and `alt+down` traverse up and down the REPL command history\n\
; when the cursor is after the last contents at the prompt\n\
; - Clojure lines in stack traces are peekable and clickable.';

export const CLJS_CONNECT_GREETINGS =
'; TIPS: You can choose which REPL to use (clj or cljs):\n\
; *Calva: Toggle REPL connection*\n\
; (There is a button in the status bar for this)';
const PROMPT_HINT = 'Use `alt+enter` to evaluate';

const START_GREETINGS = [
'This is the Calva evaluation results output window.',
'TIPS: The keyboard shortcut `ctrl+alt+o o` shows and focuses this window',
' when connected to a REPL session.',
'Please see https://calva.io/output/ for more info.',
'Happy coding! ♥️',
].join(`\n`);

export const CLJ_CONNECT_GREETINGS = [
'TIPS:',
' - You can edit the contents here. Use it as a REPL if you like.',
' - `alt+enter` evaluates the current top level form.',
' - `ctrl+enter` evaluates the current form.',
' - `alt+up` and `alt+down` traverse up and down the REPL command history',
' when the cursor is after the last contents at the prompt',
' - Clojure lines in stack traces are peekable and clickable.',
].join(`\n`);

export const CLJS_CONNECT_GREETINGS = [
'TIPS: You can choose which REPL to use (clj or cljs):',
' *Calva: Toggle REPL connection*',
' (There is a button in the status bar for this)',
].join(`\n`);

function outputFileDir() {
const projectRoot = state.getProjectRootUri();
Expand Down Expand Up @@ -71,7 +74,7 @@ export function getPrompt(): string {
let prompt = `${_sessionType}${getNs()}꞉> `;
if (showPrompt[_sessionType]) {
showPrompt[_sessionType] = false;
prompt = `${prompt} ${PROMPT_HINT}`;
prompt = `${prompt} ${formatAsLineComments(PROMPT_HINT)}`;
}
return prompt;
}
Expand Down Expand Up @@ -140,7 +143,7 @@ export async function initResultsDoc(): Promise<vscode.TextDocument> {
return resultsDoc;
}

const greetings = `${START_GREETINGS}\n\n`;
const greetings = `${formatAsLineComments(START_GREETINGS)}\n\n`;
const edit = new vscode.WorkspaceEdit();
const fullRange = new vscode.Range(resultsDoc.positionAt(0), resultsDoc.positionAt(Infinity));
edit.replace(docUri, fullRange, greetings);
Expand Down
4 changes: 2 additions & 2 deletions src/results-output/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function addToHistory(history: string[], content?: string): string[] {
return history;
}

function formatAsLineComments(error: string): string {
return `; ${error.trim().replace(/\n\r?/, '\n; ')}`;
function formatAsLineComments(str: string): string {
return `; ${str}`.replace(/\r?\n$/, '').replace(/\r?\n/g, '\n; ');
}

function splitEditQueueForTextBatching(
Expand Down
2 changes: 0 additions & 2 deletions src/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ async function reportTests(
const resultSet = result.results[ns];
for (const test in resultSet) {
for (const a of resultSet[test]) {
cider.cleanUpWhiteSpace(a);

const messages = cider.detailedMessage(a);

if (a.type == 'error') {
Expand Down
1 change: 1 addition & 0 deletions test-data/projects/frankenstein/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions test-data/projects/frankenstein/src/foo.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(ns foo)

(defn abs [])
13 changes: 13 additions & 0 deletions test-data/projects/lein-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
/.prepl-port
.hgignore
.hg/
7 changes: 7 additions & 0 deletions test-data/projects/lein-project/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(defproject lein-project "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.11.1"]]
:repl-options {:init-ns lein-project.core})
6 changes: 6 additions & 0 deletions test-data/projects/lein-project/src/lein_project/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns lein-project.core)

(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns lein-project.core-test
(:require [clojure.test :refer :all]
[lein-project.core :refer :all]))

(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
14 changes: 14 additions & 0 deletions test-data/projects/pirate-lang/test/pez/pirate_lang_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
(testing "Hear rövarspråk"
(is (= "Har du hört talas om rövarspråket?"
(sut/from-pirate-talk "HoHaror dodu hohörortot totalolasos omom rorövovarorsospoproråkoketot?" sut/swedish-o)))))

(deftest extra-lines
;; Test that Calva doesn't add or remove whitespace from test output
;; NB: "seven" and "eight" are lost, we never get them back from the nREPL server, I think
(testing "printing w/ retained whitespace"
(is (nil? (do
(print "one")
(println "two")
(println "three")
(print " four")
(println " five")
(println " six")
(print "seven")
(print "eight"))))))

0 comments on commit b526450

Please sign in to comment.