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 Dec 14, 2022
2 parents 5e124de + f54e50a commit e8d68ee
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changes to Calva.

## [Unreleased]

## [2.0.322] - 2022-12-14

- Fix: [Clojure notebooks don't seem to work on MS-Windows](https://github.com/BetterThanTomorrow/calva/issues/1994)
- Fix: [Calva development: npm run prettier-format fails on MS-Windows](https://github.com/BetterThanTomorrow/calva/issues/1996)
- Bump bundled deps.clj to v1.11.1.1208

## [2.0.321] - 2022-12-05

- Fix: [Supplying a custom printFn to the pretty printer does not work](https://github.com/BetterThanTomorrow/calva/issues/1979)
Expand Down
2 changes: 1 addition & 1 deletion deps-clj-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.11.1.1200
v1.11.1.1208
Binary file modified deps.clj.jar
Binary file not shown.
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.

10 changes: 5 additions & 5 deletions 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.321",
"version": "2.0.322",
"publisher": "betterthantomorrow",
"author": {
"name": "Better Than Tomorrow",
Expand Down Expand Up @@ -2881,10 +2881,10 @@
"integration-test": "node ./out/extension-test/integration/runTests.js",
"unit-test": "npx mocha --require ts-node/register 'src/extension-test/unit/**/*-test.ts'",
"unit-test-watch": "npx mocha --watch --require ts-node/register --watch-extensions ts --watch-files src 'src/extension-test/unit/**/*-test.ts'",
"prettier-format": "npx prettier --write './**/*.{ts,js,json}'",
"prettier-check": "npx prettier --check './**/*.{ts,js,json}'",
"prettier-check-watch": "onchange './**/*.{ts,js,json}' -- prettier --check {{changed}}",
"prettier-format-watch": "onchange './**/*.{ts,js,json}' -- prettier --write {{changed}}",
"prettier-format": "npx prettier --write \"./**/*.{ts,js,json}\"",
"prettier-check": "npx prettier --check \"./**/*.{ts,js,json}\"",
"prettier-check-watch": "onchange \"./**/*.{ts,js,json}\" -- prettier --check {{changed}}",
"prettier-format-watch": "onchange \"./**/*.{ts,js,json}\" -- prettier --write {{changed}}",
"preprettier-format-watch": "npm run prettier-format",
"eslint": "npx eslint . --ext .js,.jsx,.ts,.tsx",
"eslint-watch": "npx esw . --ext .js,.jsx,.ts,.tsx --watch"
Expand Down
13 changes: 12 additions & 1 deletion src/cursor-doc/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export function initScanner(maxLength: number) {
scanner = new Scanner(maxLength);
}

/**
* @param text The text to look in for the end of line seq.
* @returns The first end of line sequence found in TEXT, if any.
*/
export function getFirstEol(text: string) {
return text.match(/\r\n|\n/g)?.[0];
}

export class TextLine {
tokens: Token[] = [];
text: string;
Expand Down Expand Up @@ -527,14 +535,17 @@ export class LineInputModel implements EditableModel {

export class StringDocument implements EditableDocument {
constructor(contents?: string) {
const eol = contents ? getFirstEol(contents) : null;

this.model = new LineInputModel(eol ? eol.length : 1, this);
if (contents) {
this.insertString(contents);
}
}

selection: ModelEditSelection;

model: LineInputModel = new LineInputModel(1, this);
model: LineInputModel;

selectionStack: ModelEditSelection[] = [];

Expand Down
5 changes: 3 additions & 2 deletions src/cursor-doc/token-cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LineInputModel } from './model';
import { getFirstEol, LineInputModel } from './model';
import { Token, validPair } from './clojure-lexer';

function tokenIsWhiteSpace(token: Token) {
Expand Down Expand Up @@ -943,7 +943,8 @@ export class LispTokenCursor extends TokenCursor {
* Creates a `LispTokenCursor` for walking and manipulating the string `s`.
*/
export function createStringCursor(s: string): LispTokenCursor {
const model = new LineInputModel();
const eol = getFirstEol(s);
const model = new LineInputModel(eol ? eol.length : 1);
model.insertString(0, s);
return model.getTokenCursor(0);
}
6 changes: 2 additions & 4 deletions src/extension-test/unit/cursor-doc/paredit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ describe('paredit', () => {
const b = docFromTextNotation('(a| b (c\r\n d)| e)');
const [start, end] = textAndSelection(b)[1];
const actual = paredit.forwardHybridSexpRange(a);
// off by 1 because \r\n is treated as 1 char?
expect(actual).toEqual([start, end - 1]);
expect(actual).toEqual([start, end]);
});

it('Maintains balanced delimiters 2', () => {
Expand All @@ -194,8 +193,7 @@ describe('paredit', () => {
const b = docFromTextNotation('(aa| (c (e\r\nf))|g)');
const [start, end] = textAndSelection(b)[1];
const actual = paredit.forwardHybridSexpRange(a);
// off by 1 because \r\n is treated as 1 char?
expect(actual).toEqual([start, end - 1]);
expect(actual).toEqual([start, end]);
});

it('Maintains balanced delimiters 3', () => {
Expand Down
28 changes: 27 additions & 1 deletion src/extension-test/unit/cursor-doc/token-cursor-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as expect from 'expect';
import { LispTokenCursor } from '../../../cursor-doc/token-cursor';
import { createStringCursor, LispTokenCursor } from '../../../cursor-doc/token-cursor';
import { docFromTextNotation, textAndSelection } from '../common/text-notation';

describe('Token Cursor', () => {
Expand Down Expand Up @@ -28,6 +28,20 @@ describe('Token Cursor', () => {
cursor.forwardSexp();
expect(cursor.offsetStart).toBe(b.selection.anchor);
});
it('forwardSexp with newline', () => {
const a = docFromTextNotation('|(a\n(b))');
const b = docFromTextNotation('(a\n(b))|');
const cursor: LispTokenCursor = a.getTokenCursor(a.selection.anchor);
cursor.forwardSexp();
expect(cursor.offsetStart).toBe(b.selection.anchor);
});
it('forwardSexp with newline (MS-Windows)', () => {
const a = docFromTextNotation('|(a\r\n(b))');
const b = docFromTextNotation('(a\r\n(b))|');
const cursor: LispTokenCursor = a.getTokenCursor(a.selection.anchor);
cursor.forwardSexp();
expect(cursor.offsetStart).toBe(b.selection.anchor);
});
it('moves from beginning to end of nested list ', () => {
const a = docFromTextNotation('|(a(b(c•#f•(#b •[:f])•#z•1)))');
const b = docFromTextNotation('(a(b(c•#f•(#b •[:f])•#z•1)))|');
Expand Down Expand Up @@ -876,6 +890,18 @@ describe('Token Cursor', () => {
expect(cursor.getFunctionName()).toBeUndefined();
});
});
describe('createStringCursor', () => {
it('Ranges account for newline', () => {
const cursor = createStringCursor('(a\n(b))');
const topLevelRanges = cursor.rangesForTopLevelForms().flat();
expect(topLevelRanges).toEqual([0, 7]);
});
it('Ranges account for newline (MS-Windows)', () => {
const cursor = createStringCursor('(a\r\n(b))');
const topLevelRanges = cursor.rangesForTopLevelForms().flat();
expect(topLevelRanges).toEqual([0, 8]);
});
});
});

describe('Location State', () => {
Expand Down

0 comments on commit e8d68ee

Please sign in to comment.