diff --git a/src/cljConnection.ts b/src/cljConnection.ts index 70a2949..30ccf7b 100644 --- a/src/cljConnection.ts +++ b/src/cljConnection.ts @@ -154,7 +154,7 @@ const disconnect = (showMessage: boolean = true): void => { vscode.window.showWarningMessage('Not connected to any nREPL.'); }; -const getLocalNReplPort = (): number => { +const getLocalNReplPort = (): number | undefined => { const projectDir = vscode.workspace.rootPath; if (projectDir) { @@ -164,7 +164,9 @@ const getLocalNReplPort = (): number => { } const homeDir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; - return getPortFromFS(path.join(homeDir, '.lein', 'repl-port')); + if (homeDir) { + return getPortFromFS(path.join(homeDir, '.lein', 'repl-port')); + } }; const getPortFromFS = (path: string): number => fs.existsSync(path) ? Number.parseInt(fs.readFileSync(path, 'utf-8')) : NaN; diff --git a/src/clojureEval.ts b/src/clojureEval.ts index 10d9a9e..f671196 100644 --- a/src/clojureEval.ts +++ b/src/clojureEval.ts @@ -118,9 +118,16 @@ function runTests(outputChannel: vscode.OutputChannel, listener: TestListener, n export function testNamespace(outputChannel: vscode.OutputChannel, listener: TestListener): void { const editor = vscode.window.activeTextEditor; - const ns = cljParser.getNamespace(editor.document.getText()); // log ns and 'starting' - outputChannel.appendLine("Testing " + ns) - runTests(outputChannel, listener, ns); + if (editor) { + const text = editor.document.getText(); + const ns = cljParser.getNamespace(text); // log ns and 'starting' + outputChannel.appendLine("Testing " + ns) + runTests(outputChannel, listener, ns); + } else { + // if having troubles with finding the namespace (though I'm not sure + // if it can actually happen), run all tests + runAllTests(outputChannel, listener); + } } export function runAllTests(outputChannel: vscode.OutputChannel, listener: TestListener): void { diff --git a/src/nreplClient.ts b/src/nreplClient.ts index dcd62df..030c6b2 100644 --- a/src/nreplClient.ts +++ b/src/nreplClient.ts @@ -74,7 +74,7 @@ const evaluateFile = (code: string, filepath: string, session?: string): Promise const stacktrace = (session: string): Promise => send({ op: 'stacktrace', session: session }); -const runTests = function (namespace: string): Promise { +const runTests = function (namespace: string | undefined): Promise { const message: TestMessage = { op: (namespace ? "test" : "test-all"), ns: namespace, @@ -84,7 +84,7 @@ const runTests = function (namespace: string): Promise { } -const clone = (session?: string): Promise => send({ op: 'clone', session: session }).then(respObjs => respObjs[0]); +const clone = (session?: string): Promise => send({ op: 'clone', session: session }).then(respObjs => respObjs[0]); const test = (connectionInfo: CljConnectionInformation): Promise => { return send({ op: 'clone' }, connectionInfo)