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 Mar 18, 2022
2 parents dcf8f1f + b9ea42a commit c569e21
Show file tree
Hide file tree
Showing 48 changed files with 445 additions and 306 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changes to Calva.

## [Unreleased]

## [2.0.255] - 2022-03-18
- Maintenance: [Update more TypeScript code to be compatible with strictNullChecks.](https://github.com/BetterThanTomorrow/calva/pull/1581)

## [2.0.254] - 2022-03-16
- [Add commands for starting and stopping clojure-lsp](https://github.com/BetterThanTomorrow/calva/pull/1592)
- Maintenance: [Dumb down the token cursor some dealing with meta data and readers](https://github.com/BetterThanTomorrow/calva/pull/1585)
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.254",
"version": "2.0.255",
"publisher": "betterthantomorrow",
"author": {
"name": "Better Than Tomorrow",
Expand Down
2 changes: 1 addition & 1 deletion src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Analytics {
);
}

private userID(): string {
private userID(): string | undefined {
const KEY = 'userLogID';
if (this.store.get(KEY) == undefined) {
const newID = uuid.uuid();
Expand Down
14 changes: 7 additions & 7 deletions src/calva-fmt/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getIndent,
getDocumentOffset,
MirroredDocument,
mustGetDocument,
getDocument,
} from '../../doc-mirror/index';
import {
formatTextAtRange,
Expand All @@ -21,10 +21,10 @@ export async function indentPosition(
position: vscode.Position,
document: vscode.TextDocument
) {
const editor = util.mustGetActiveTextEditor();
const editor = util.getActiveTextEditor();
const pos = new vscode.Position(position.line, 0);
const indent = getIndent(
mustGetDocument(document).model.lineInputModel,
getDocument(document).model.lineInputModel,
getDocumentOffset(document, position),
await config.getConfig()
);
Expand Down Expand Up @@ -54,9 +54,9 @@ export async function indentPosition(
export async function formatRangeEdits(
document: vscode.TextDocument,
range: vscode.Range
): Promise<vscode.TextEdit[]> {
): Promise<vscode.TextEdit[] | undefined> {
const text: string = document.getText(range);
const mirroredDoc: MirroredDocument = mustGetDocument(document);
const mirroredDoc: MirroredDocument = getDocument(document);
const startIndex = document.offsetAt(range.start);
const endIndex = document.offsetAt(range.end);
const cursor = mirroredDoc.getTokenCursor(startIndex);
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function formatPositionInfo(
const doc: vscode.TextDocument = editor.document;
const pos: vscode.Position = editor.selection.active;
const index = doc.offsetAt(pos);
const mirroredDoc: MirroredDocument = mustGetDocument(doc);
const mirroredDoc: MirroredDocument = getDocument(doc);
const cursor = mirroredDoc.getTokenCursor(index);
const formatDepth = extraConfig['format-depth']
? extraConfig['format-depth']
Expand Down Expand Up @@ -240,7 +240,7 @@ async function _formatRange(
allText: string,
range: number[],
eol: string
): Promise<string> {
): Promise<string | undefined> {
const d = {
'range-text': rangeText,
'all-text': allText,
Expand Down
15 changes: 7 additions & 8 deletions src/calva-fmt/src/providers/ontype_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FormatOnTypeEditProvider
_position: vscode.Position,
ch: string,
_options
): Promise<vscode.TextEdit[]> {
): Promise<vscode.TextEdit[] | undefined> {
let keyMap = vscode.workspace
.getConfiguration()
.get('calva.paredit.defaultKeyMap');
Expand All @@ -24,21 +24,20 @@ export class FormatOnTypeEditProvider
keyMap === 'strict' &&
getConfig().strictPreventUnmatchedClosingBracket
) {
const mDoc: EditableDocument =
docMirror.mustGetDocument(document);
const mDoc: EditableDocument = docMirror.getDocument(document);
const tokenCursor = mDoc.getTokenCursor();
if (tokenCursor.withinComment()) {
return null;
return undefined;
}
return paredit.backspace(mDoc).then((fulfilled) => {
paredit.close(mDoc, ch);
return null;
return undefined;
});
} else {
return null;
return undefined;
}
}
const editor = util.mustGetActiveTextEditor();
const editor = util.getActiveTextEditor();

const pos = editor.selection.active;
if (
Expand All @@ -61,6 +60,6 @@ export class FormatOnTypeEditProvider
}
}

return null;
return undefined;
}
}
12 changes: 6 additions & 6 deletions src/clojuredocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function printTextToRichCommentCommand(args: { [x: string]: string }) {

function printTextToRichComment(text: string, position?: number) {
const doc = util.getDocument({});
const mirrorDoc = docMirror.mustGetDocument(doc);
const mirrorDoc = docMirror.getDocument(doc);
paredit.addRichComment(
mirrorDoc,
position ? position : mirrorDoc.selection.active,
Expand All @@ -74,10 +74,10 @@ function printTextToRichComment(text: string, position?: number) {
export async function getExamplesHover(
document: vscode.TextDocument,
position: vscode.Position
): Promise<vscode.MarkdownString> {
): Promise<vscode.MarkdownString | undefined> {
const docs = await clojureDocsLookup(document, position);
if (!docs) {
return null;
return undefined;
}
return getHoverForDocs(
docs,
Expand Down Expand Up @@ -183,7 +183,7 @@ async function clojureDocsLookup(
p?: vscode.Position
): Promise<DocsEntry> {
const doc = d ? d : util.getDocument({});
const position = p ? p : util.mustGetActiveTextEditor().selection.active;
const position = p ? p : util.getActiveTextEditor().selection.active;
const symbol = util.getWordAtPosition(doc, position);
const ns = namespace.getNamespace(doc);
const session = replSession.getSession(util.getFileType(doc));
Expand Down Expand Up @@ -237,7 +237,7 @@ function rawDocs2DocsEntry(
docsResult: any,
symbol: string,
ns: string
): DocsEntry {
): DocsEntry | undefined {
const docs = docsResult.clojuredocs;
if (docs) {
return {
Expand All @@ -262,6 +262,6 @@ function rawDocs2DocsEntry(
};
} else {
// console.log(`No results for ${ns}/${symbol} from ${docsResult.fromServer}`);
return null;
return undefined;
}
}
18 changes: 9 additions & 9 deletions src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ type connectFn = (
session: NReplSession,
name: string,
checkSuccess: checkConnectedFn
) => Promise<boolean>;
) => Promise<boolean | undefined>;

async function evalConnectCode(
newCljsSession: NReplSession,
Expand All @@ -249,8 +249,8 @@ async function evalConnectCode(
errorProcessors: processOutputFn[] = []
): Promise<boolean> {
const chan = state.connectionLogChannel();
const err = [],
out = [],
const err: string[] = [],
out: string[] = [],
result = newCljsSession.eval(code, 'user', {
stdout: (x) => {
out.push(util.stripAnsi(x));
Expand Down Expand Up @@ -290,15 +290,17 @@ export interface ReplType {

let translatedReplType: ReplType;

async function figwheelOrShadowBuilds(cljsTypeName: string): Promise<string[]> {
async function figwheelOrShadowBuilds(
cljsTypeName: string
): Promise<string[] | undefined> {
if (cljsTypeName.includes('Figwheel Main')) {
return await getFigwheelMainBuilds();
} else if (cljsTypeName.includes('shadow-cljs')) {
return await projectTypes.shadowBuilds();
}
}

function updateInitCode(build: string, initCode): string {
function updateInitCode(build: string, initCode): string | undefined {
if (build && typeof initCode === 'object') {
if (['node-repl', 'browser-repl'].includes(build)) {
return initCode.repl.replace('%REPL%', build);
Expand All @@ -308,7 +310,7 @@ function updateInitCode(build: string, initCode): string {
} else if (build && typeof initCode === 'string') {
return initCode.replace('%BUILD%', `"${build}"`);
}
return null;
return undefined;
}

function createCLJSReplType(
Expand Down Expand Up @@ -836,9 +838,7 @@ export default {
}
setStateValue('cljc', newSession);
if (
outputWindow.isResultsDoc(
util.mustGetActiveTextEditor().document
)
outputWindow.isResultsDoc(util.getActiveTextEditor().document)
) {
outputWindow.setSession(newSession, undefined);
replSession.updateReplSessionType();
Expand Down
9 changes: 8 additions & 1 deletion src/cursor-doc/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Scanner, Token, ScannerState } from './clojure-lexer';
import { LispTokenCursor } from './token-cursor';
import { deepEqual as equal } from '../util/object';
import { isUndefined } from 'lodash';

let scanner: Scanner;

Expand Down Expand Up @@ -291,7 +292,7 @@ export class LineInputModel implements EditableModel {
const st = this.getRowCol(Math.min(start, end));
const en = this.getRowCol(Math.max(start, end));

const lines = [];
const lines: string[] = [];
if (st[0] == en[0]) {
lines[0] = this.lines[st[0]].text.substring(st[1], en[1]);
} else {
Expand Down Expand Up @@ -581,6 +582,8 @@ export class LineInputModel implements EditableModel {
lastIndex = i;
}
return new LispTokenCursor(this, row, line.tokens.length - 1);
} else {
throw new Error('Unable to get token cursor for LineInputModel!');
}
}
}
Expand Down Expand Up @@ -609,6 +612,10 @@ export class StringDocument implements EditableDocument {
selectionStack: ModelEditSelection[] = [];

getTokenCursor(offset?: number, previous?: boolean): LispTokenCursor {
if (isUndefined(offset)) {
throw new Error('Expected a cursor for StringDocument!');
}

return this.model.getTokenCursor(offset);
}

Expand Down
4 changes: 2 additions & 2 deletions src/cursor-doc/paredit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,10 @@ export function backspace(
start: number = doc.selection.anchor,
end: number = doc.selection.active
): Thenable<boolean> {
const cursor = doc.getTokenCursor(start);
if (start != end) {
return doc.backspace();
} else {
const cursor = doc.getTokenCursor(start);
const nextToken = cursor.getToken();
const p = start;
const prevToken =
Expand Down Expand Up @@ -857,10 +857,10 @@ export function deleteForward(
start: number = doc.selectionLeft,
end: number = doc.selectionRight
) {
const cursor = doc.getTokenCursor(start);
if (start != end) {
void doc.delete();
} else {
const cursor = doc.getTokenCursor(start);
const prevToken = cursor.getPrevToken();
const nextToken = cursor.getToken();
const p = start;
Expand Down
2 changes: 1 addition & 1 deletion src/custom-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function evaluateCustomCodeSnippetCommand(codeOrKey?: string) {
}

async function evaluateCodeOrKey(codeOrKey?: string) {
const editor = util.mustGetActiveTextEditor();
const editor = util.getActiveTextEditor();
const currentLine = editor.selection.active.line;
const currentColumn = editor.selection.active.character;
const currentFilename = editor.document.fileName;
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/calva-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class CalvaDebugSession extends LoggingDebugSession {
new Position(positionLine, positionColumn)
);
const tokenCursor = docMirror
.mustGetDocument(document)
.getDocument(document)
.getTokenCursor(offset);

try {
Expand Down
4 changes: 2 additions & 2 deletions src/debugger/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function triggerUpdateAndRenderDecorations() {
timeout = undefined;
}
if (enabled) {
const editor = util.getActiveTextEditor();
const editor = util.tryToGetActiveTextEditor();
if (editor) {
timeout = setTimeout(() => {
const cljSession = replSession.getSession('clj');
Expand All @@ -166,7 +166,7 @@ function activate() {
});

vscode.workspace.onDidChangeTextDocument((event) => {
const activeEditor = util.getActiveTextEditor();
const activeEditor = util.tryToGetActiveTextEditor();
if (
activeEditor &&
event.document === activeEditor.document &&
Expand Down
Loading

0 comments on commit c569e21

Please sign in to comment.