Skip to content

Commit

Permalink
connect
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Feb 10, 2021
1 parent 4e79b9f commit 1fbe5f3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@
"${workspaceFolder}/dist/**/*.js"
]
},
{
"name": "Launch w/ no folder",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--folder-uri=null"
],
"stopOnEntry": false,
"sourceMaps": true,
"env": {
"CALVA_DEV_GA": "FUBAR-69796730-4",
"DEBUG": "no-debug-universal-analytics"
},
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
},
{
"name": "Theia node launch",
"type": "node",
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
],
"activationEvents": [
"onLanguage:clojure",
"onCommand:calva.startNewRepl",
"onCommand:calva.jackIn",
"onCommand:calva.jackInOrConnect",
"onCommand:calva.connect",
Expand Down Expand Up @@ -662,6 +663,11 @@
"enablement": "!calva:connected && !calva:connecting",
"category": "Calva"
},
{
"command": "calva.startNewRepl",
"title": "Start a Clojure REPL",
"category": "Calva"
},
{
"command": "calva.toggleCLJCSession",
"title": "Toggle the REPL Connection (clj or cljs) used for CLJC Files",
Expand Down Expand Up @@ -1234,6 +1240,10 @@
"key": "ctrl+alt+c ctrl+alt+c",
"when": "calva:keybindingsEnabled"
},
{
"command": "calva.startNewRepl",
"key": "ctrl+alt+c ctrl+alt+r"
},
{
"command": "calva.connectNonProjectREPL",
"key": "ctrl+alt+c alt+c",
Expand Down Expand Up @@ -1717,6 +1727,10 @@
"command": "calva.jackInOrConnect",
"when": "false"
},
{
"command": "calva.startNewRepl",
"when": "true"
},
{
"command": "calva.debug.instrument",
"when": "editorLangId == clojure && calva:connected"
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async function activate(context: vscode.ExtensionContext) {

// COMMANDS
context.subscriptions.push(vscode.commands.registerCommand('calva.jackInOrConnect', jackIn.calvaJackInOrConnect));
context.subscriptions.push(vscode.commands.registerCommand('calva.startNewRepl', jackIn.calvaJackInOrConnect));
context.subscriptions.push(vscode.commands.registerCommand('calva.jackIn', jackIn.calvaJackIn));
context.subscriptions.push(vscode.commands.registerCommand('calva.copyJackInCommandToClipboard', jackIn.copyJackInCommandToClipboard));
context.subscriptions.push(vscode.commands.registerCommand('calva.connectNonProjectREPL', connector.connectNonProjectREPLCommand));
Expand Down
16 changes: 9 additions & 7 deletions src/files-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ function writeToCache(uri: vscode.Uri) {
*/
export const content = (path: string) => {
const resolvedPath = state.resolvePath(path);
if (!filesCache.has(resolvedPath)) {
writeToCache(vscode.Uri.file(resolvedPath));
const filesWatcher = vscode.workspace.createFileSystemWatcher(resolvedPath);
filesWatcher.onDidChange(writeToCache);
filesWatcher.onDidCreate(writeToCache);
filesWatcher.onDidDelete((uri) => filesCache.delete(uri.fsPath));
if (resolvedPath) {
if (!filesCache.has(resolvedPath)) {
writeToCache(vscode.Uri.file(resolvedPath));
const filesWatcher = vscode.workspace.createFileSystemWatcher(resolvedPath);
filesWatcher.onDidChange(writeToCache);
filesWatcher.onDidCreate(writeToCache);
filesWatcher.onDidDelete((uri) => filesCache.delete(uri.fsPath));
}
return filesCache.get(resolvedPath);
}
return filesCache.get(resolvedPath);
};
4 changes: 3 additions & 1 deletion src/nrepl/connectSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ function getDefaultCljsType(cljsType: string): CljsTypeConfig {
async function askForConnectSequence(cljTypes: string[], saveAs: string, logLabel: string): Promise<ReplConnectSequence> {
// figure out what possible kinds of project we're in
const sequences: ReplConnectSequence[] = getConnectSequences(cljTypes);
const projectRootUri = state.getProjectRootUri();
const saveAsFull = projectRootUri ? `${projectRootUri.toString()}/${saveAs}` : saveAs;
const projectConnectSequenceName = await utilities.quickPickSingle({
values: sequences.map(s => { return s.name }),
placeHolder: "Please select a project type",
saveAs: `${state.getProjectRootUri().toString()}/${saveAs}`,
saveAs: saveAsFull,
autoSelect: true
});
if (!projectConnectSequenceName || projectConnectSequenceName.length <= 0) {
Expand Down
13 changes: 10 additions & 3 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,20 @@ export async function calvaDisconnect() {
}

export async function calvaJackInOrConnect() {

const JACK_IN_OPTION = "Start a REPL server and connect (a.k.a. Jack-in)";
const JACK_IN_COMMAND = "calva.jackIn";
let commands = {};
if (!utilities.getConnectedState() &&
!utilities.getConnectingState() &&
!utilities.getLaunchingState()) {
if (vscode.workspace.workspaceFolders[0].uri.scheme != "vsls") {
commands["Start a REPL server and connect (a.k.a. Jack-in)"] = "calva.jackIn";

if (vscode.workspace.workspaceFolders &&
vscode.workspace.workspaceFolders.length > 0) {
if (vscode.workspace.workspaceFolders[0].uri.scheme != "vsls") {
commands[JACK_IN_OPTION] = JACK_IN_COMMAND;
}
} else {
commands[JACK_IN_OPTION] = JACK_IN_COMMAND;
}
commands["Connect to a running REPL server in your project"] = "calva.connect";
commands["Connect to a running REPL server, not in your project"] = "calva.connectNonProjectREPL";
Expand Down
12 changes: 8 additions & 4 deletions src/results-output/results-doc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as vscode from 'vscode';
import * as os from 'os';
import * as state from '../state';
import { highlight } from '../highlight/src/extension'
import { NReplSession } from '../nrepl';
Expand Down Expand Up @@ -35,13 +36,16 @@ export const CLJS_CONNECT_GREETINGS = '; TIPS: You can choose which REPL to use
; *Calva: Toggle REPL connection*\n\
; (There is a button in the status bar for this)';

const OUTPUT_FILE_DIR = () => {
const projectRoot = state.getProjectRootUri();
function outputFileDir() {
let projectRoot = state.getProjectRootUri();
if (!projectRoot) {
projectRoot = vscode.Uri.file(os.tmpdir());
}
return vscode.Uri.joinPath(projectRoot, ".calva", "output-window");
};

const DOC_URI = () => {
return vscode.Uri.joinPath(OUTPUT_FILE_DIR(), RESULTS_DOC_NAME);
return vscode.Uri.joinPath(outputFileDir(), RESULTS_DOC_NAME);
};

let _sessionType: ReplSessionType = "clj";
Expand Down Expand Up @@ -114,7 +118,7 @@ export function setContextForOutputWindowActive(isActive: boolean): void {
}

export async function initResultsDoc(): Promise<vscode.TextDocument> {
await vscode.workspace.fs.createDirectory(OUTPUT_FILE_DIR());
await vscode.workspace.fs.createDirectory(outputFileDir());
let resultsDoc: vscode.TextDocument;
try {
resultsDoc = await vscode.workspace.openTextDocument(DOC_URI());
Expand Down
2 changes: 1 addition & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function getProjectWsFolder(): vscode.WorkspaceFolder {
return folder;
}
}
if (vscode.workspace.workspaceFolders) {
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
return vscode.workspace.workspaceFolders[0];
}
return undefined;
Expand Down

0 comments on commit 1fbe5f3

Please sign in to comment.