Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload ns #80

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
143f888
add flag to silent the eval alert + reload namespace command + auto r…
barakl-madlan Dec 15, 2017
76ea252
move common methods to one function for code reusability
barakl-madlan Dec 16, 2017
6a3b146
add utils.ts
barakliato Dec 16, 2017
f05f222
remove console.log
barakliato Dec 16, 2017
ed95089
fix bud were error return from eval use promise reject in then instea…
barakliato Dec 17, 2017
912ae63
ignore files that dosen't ends with .clj when reloading namespace
barakliato Dec 17, 2017
151b6ef
remove the alert when the repl is not connected
barakliato Dec 17, 2017
c01f8f8
add eastwood linter support
barakliato Dec 18, 2017
fe2e541
add exception support in linter
barakliato Dec 18, 2017
86a9249
point to the correct line on exception
barakliato Dec 18, 2017
e0452f9
take one character back in linter exception
barakliato Dec 18, 2017
96bba74
clear the problems before linting on save
barakliato Dec 18, 2017
c315956
fix bug in linter
barakliato Dec 18, 2017
f21075e
don't color the entire file when there is EOF exception
barakliato Dec 18, 2017
901e09f
handle more errors
barakliato Dec 20, 2017
c6c1a23
add command and props
barakliato Dec 20, 2017
ac08f91
change the command reloadNamespace to clojureVSCode.reloadNamespace
barakliato Dec 20, 2017
4bf27fe
disable linting if eastwood is not available - check if it becomes av…
barakliato Dec 24, 2017
9794959
during work on symbol search + fix a bug in linter
barakliato Dec 25, 2017
522afaa
add search by symbol
barakliato Dec 30, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
{
"name": "Alessandro Decina",
"email": "[email protected]"
},
{
"name": "Barak Liato",
"email": "[email protected]"
}
],
"license": "MIT",
Expand All @@ -52,7 +56,8 @@
"Other"
],
"activationEvents": [
"onLanguage:clojure"
"onCommand:clojureVSCode.startNRepl",
"onCommand:clojureVSCode.manuallyConnectToNRepl"
],
"main": "./out/src/clojureMain",
"contributes": {
Expand Down Expand Up @@ -80,6 +85,14 @@
{
"command": "clojureVSCode.formatFile",
"title": "Clojure: Format file or selection"
},
{
"command": "clojureVSCode.reloadNamespace",
"title": "reload the current namespace"
},
{
"command": "clojureVSCode.searchSymbol",
"title": "Try to find the symbol and add its namespace to the decleration"
}
],
"configuration": {
Expand All @@ -95,6 +108,16 @@
"type": "boolean",
"default": false,
"description": "Format the code on save."
},
"clojureVSCode.alertOnEval": {
"type": "boolean",
"default": true,
"description": "show pop up alert on eval."
},
"clojureVSCode.autoReloadNamespaceOnSave": {
"type": "boolean",
"default": true,
"description": "auto reload the file upon save."
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cljConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ export const cljConnection = {
startNRepl,
disconnect,
sessionForFilename
};
};
34 changes: 34 additions & 0 deletions src/cljParser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TextDocument, Range, Position, CompletionList } from "vscode";

interface ExpressionInfo {
functionName: string;
parameterPosition: number;
Expand Down Expand Up @@ -135,8 +137,40 @@ const getNamespace = (text: string): string => {
return m ? m[1] : 'user';
};

//assume the position is before the block directly
const getDirectlyBeforeBlockRange = (editor: TextDocument, line: number, column: number): Range => {
const lastLineNumber = editor.lineCount - 1;
const lastLine = editor.lineAt(lastLineNumber);
const range = new Range(line, column, lastLineNumber, lastLine.range.end.character);
const text = editor.getText(range);

let count = 0;
let endPosition = new Position(line, column);
let c = column;
for(let l = line; l < range.end.line;) {
const currentLine = editor.lineAt(l);
for(;c < currentLine.range.end.character;c++) {
if(text[c] === '(')
count++;

if(text[c] === ')')
count--;
}

if(count === 0) {
return new Range(line - 1, column, l - 1, c);
}

l++;
c = 0;
}

return new Range(line, column, line, column);
}

export const cljParser = {
R_CLJ_WHITE_SPACE,
getExpressionInfo,
getNamespace,
getDirectlyBeforeBlockRange
};
57 changes: 33 additions & 24 deletions src/clojureEval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,35 @@ import * as vscode from 'vscode';
import { cljConnection } from './cljConnection';
import { cljParser } from './cljParser';
import { nreplClient } from './nreplClient';
import {readBooleanConfiguration} from './utils';

export function clojureEval(outputChannel: vscode.OutputChannel): void {
function getAlertOnEvalResult() {
return readBooleanConfiguration('aletOnEval');
}

export function clojureEval(outputChannel: vscode.OutputChannel): void {
evaluate(outputChannel, false);
}

export function clojureEvalAndShowResult(outputChannel: vscode.OutputChannel): void {
export function clojureEvalAndShowResult(outputChannel: vscode.OutputChannel): void {
evaluate(outputChannel, true);
}

export function evaluateText(outputChannel: vscode.OutputChannel,
showResults: boolean,
fileName: string,
text: string): Promise<any[]> {
return cljConnection.sessionForFilename(fileName).then(session => {
return (fileName.length === 0 && session.type == 'ClojureScript')
// Piggieback's evalFile() ignores the text sent as part of the request
// and just loads the whole file content from disk. So we use eval()
// here, which as a drawback will give us a random temporary filename in
// the stacktrace should an exception occur.
? nreplClient.evaluate(text, session.id)
: nreplClient.evaluateFile(text, fileName, session.id);
});
}

function evaluate(outputChannel: vscode.OutputChannel, showResults: boolean): void {
if (!cljConnection.isConnected()) {
vscode.window.showWarningMessage('You should connect to nREPL first to evaluate code.');
Expand All @@ -26,28 +46,17 @@ function evaluate(outputChannel: vscode.OutputChannel, showResults: boolean): vo
text = `(ns ${ns})\n${editor.document.getText(selection)}`;
}

cljConnection.sessionForFilename(editor.document.fileName).then(session => {
let response;
if (!selection.isEmpty && session.type == 'ClojureScript') {
// Piggieback's evalFile() ignores the text sent as part of the request
// and just loads the whole file content from disk. So we use eval()
// here, which as a drawback will give us a random temporary filename in
// the stacktrace should an exception occur.
response = nreplClient.evaluate(text, session.id);
} else {
response = nreplClient.evaluateFile(text, editor.document.fileName, session.id);
}
response.then(respObjs => {
if (!!respObjs[0].ex)
return handleError(outputChannel, selection, showResults, respObjs[0].session);

return handleSuccess(outputChannel, showResults, respObjs);
})
});
evaluateText(outputChannel, showResults, editor.document.fileName, text)
.then(respObjs => {
if (!!respObjs[0].ex)
return handleError(outputChannel, selection, showResults, respObjs[0].session);

return handleSuccess(outputChannel, showResults, respObjs);
});
}

function handleError(outputChannel: vscode.OutputChannel, selection: vscode.Selection, showResults: boolean, session: string): Promise<void> {
if (!showResults)
export function handleError(outputChannel: vscode.OutputChannel, selection: vscode.Selection, showResults: boolean, session: string): Promise<void> {
if (!showResults && getAlertOnEvalResult())
vscode.window.showErrorMessage('Compilation error');

return nreplClient.stacktrace(session)
Expand Down Expand Up @@ -75,8 +84,8 @@ function handleError(outputChannel: vscode.OutputChannel, selection: vscode.Sele
});
}

function handleSuccess(outputChannel: vscode.OutputChannel, showResults: boolean, respObjs: any[]): void {
if (!showResults) {
export function handleSuccess(outputChannel: vscode.OutputChannel, showResults: boolean, respObjs: any[]): void {
if (!showResults && getAlertOnEvalResult()) {
vscode.window.showInformationMessage('Successfully compiled');
} else {
respObjs.forEach(respObj => {
Expand Down
Loading