Skip to content

Commit

Permalink
Add command ”transfering” current file ns to output window
Browse files Browse the repository at this point in the history
Use default shortcut from old REPL window
Addressing #711
  • Loading branch information
PEZ committed Aug 2, 2020
1 parent e21bf0c commit 0a2024b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,12 @@
"command": "calva.showOutputWindow",
"title": "Show Output Window",
"enablement": "calva:connected"
},
{
"command": "calva.setOutputWindowNamespace",
"title": "Switch Namespace in Output Window to Current Namespace",
"enablement": "calva:connected",
"category": "Calva"
}
],
"keybindings": [
Expand Down Expand Up @@ -1247,10 +1253,6 @@
"command": "calva.loadNamespace",
"key": "ctrl+alt+c ctrl+alt+n"
},
{
"command": "calva.setREPLNamespace",
"key": "ctrl+alt+c alt+n"
},
{
"command": "calva.evalCurrentFormInREPLWindow",
"key": "ctrl+alt+c ctrl+alt+e",
Expand Down Expand Up @@ -1622,7 +1624,12 @@
{
"command": "calva.showOutputWindow",
"key": "ctrl+alt+c o",
"when": "calva:connected"
"when": "calva:connected && !calva.outputWindowActive"
},
{
"command": "calva.setOutputWindowNamespace",
"key": "ctrl+alt+c alt+n",
"when": "editorLangId == clojure && calva:connected && !calva:outputWindowActive"
}
],
"menus": {
Expand Down Expand Up @@ -1824,4 +1831,4 @@
"extensionDependencies": [
"borkdude.clj-kondo"
]
}
}
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(vscode.commands.registerCommand('calva.runCustomREPLCommand', eval.evaluateCustomCommandSnippetCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.showOutputWindow', () => { outputWindow.revealResultsDoc(false) }));
context.subscriptions.push(vscode.commands.registerCommand('calva.setOutputWindowNamespace', outputWindow.setNamespaceFromCurrentFile));

// Temporary command to teach new default keyboard shortcut chording key
context.subscriptions.push(vscode.commands.registerCommand('calva.tellAboutNewChordingKey', () => {
Expand All @@ -168,6 +169,7 @@ function activate(context: vscode.ExtensionContext) {

// Initial set of the provided contexts
vscode.commands.executeCommand("setContext", "calva:replWindowActive", false);
vscode.commands.executeCommand("setContext", "calva:outputWindowActive", false);
vscode.commands.executeCommand("setContext", "calva:launching", false);
vscode.commands.executeCommand("setContext", "calva:connected", false);
vscode.commands.executeCommand("setContext", "calva:connecting", false);
Expand Down
19 changes: 15 additions & 4 deletions src/result-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getSession(): NReplSession {
return _sessionInfo[_sessionType].session;
}

export function setSession(session: NReplSession, newNs: string): void {
export function setSession(session: NReplSession, newNs: string, onPromptAdded: OnResultAppendedCallback = null): void {
if (session) {
if (session.replType) {
_sessionType = session.replType;
Expand All @@ -56,7 +56,7 @@ export function setSession(session: NReplSession, newNs: string): void {
_sessionInfo[_sessionType].ns = newNs;
}
_prompt = `${_sessionType}::${getNs()}=> `;
appendToResultsDoc(_prompt, null);
appendToResultsDoc(_prompt, onPromptAdded);
}

export function isResultsDoc(doc: vscode.TextDocument): boolean {
Expand Down Expand Up @@ -109,7 +109,9 @@ export async function initResultsDoc(): Promise<vscode.TextDocument> {
resultsEditor.revealRange(new vscode.Range(firstPos, firstPos));
// For some reason onDidChangeTextEditorViewColumn won't fire
state.extensionContext.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(event => {
if (isResultsDoc(event.document)) {
const isOutputWindow = isResultsDoc(event.document);
vscode.commands.executeCommand("setContext", "calva:outputWindowActive", isOutputWindow);
if (isOutputWindow) {
setViewColumn(event.viewColumn);
}
}));
Expand All @@ -127,6 +129,15 @@ export function revealResultsDoc(preserveFocus: boolean = true) {
});
}

export function setNamespaceFromCurrentFile() {
const session = util.getSession();
const ns = util.getNamespace(util.getDocument({}));
setSession(session, ns, _ => {
revealResultsDoc(false);
util.updateREPLSessionType();
});
}

let scrollToBottomSub: vscode.Disposable;
interface OnResultAppendedCallback {
(insertLocation: vscode.Location): any
Expand Down Expand Up @@ -228,4 +239,4 @@ function scrollToBottom(editor: vscode.TextEditor) {

export {
OnResultAppendedCallback
};
};

0 comments on commit 0a2024b

Please sign in to comment.