Skip to content

Commit

Permalink
Change getWorkspaceConfig to getConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bpringe committed Mar 10, 2021
1 parent b565c04 commit 2a20e8e
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/calva-fmt/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as calvaConfig from '../../config';

function getLanguageConfiguration(autoIndentOn: boolean): vscode.LanguageConfiguration {
return {
onEnterRules: autoIndentOn && calvaConfig.getWorkspaceConfig().format ? [
onEnterRules: autoIndentOn && calvaConfig.getConfig().format ? [
// When Calva is the formatter disable all vscode default indentation
// (By outdenting a lot, which is the only way I have found that works)
// TODO: Make it actually consider whether Calva is the formatter or not
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const documentSelector = [
}

// TODO find a way to validate the configs
function getWorkspaceConfig() {
function getConfig() {
const configOptions = vscode.workspace.getConfiguration('calva');
return {
format: configOptions.get("formatOnSave"),
Expand Down Expand Up @@ -64,5 +64,5 @@ export {
KEYBINDINGS_ENABLED_CONTEXT_KEY,
documentSelector,
ReplSessionType,
getWorkspaceConfig
getConfig
}
10 changes: 5 additions & 5 deletions src/custom-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as getText from './util/get-text';
import * as namespace from './namespace';
import * as outputWindow from './results-output/results-doc'
import { customREPLCommandSnippet } from './evaluate';
import { getWorkspaceConfig } from './config';
import { getConfig } from './config';
import * as replSession from './nrepl/repl-session';
import * as evaluate from './evaluate';

Expand All @@ -20,15 +20,15 @@ async function evaluateCustomCodeSnippet(codeOrKey?: string): Promise<void> {
const currentFilename = editor.document.fileName;
let pickCounter = 0;
let configErrors: { "name": string; "keys": string[]; }[] = [];
const globalSnippets = getWorkspaceConfig().customREPLCommandSnippetsGlobal as customREPLCommandSnippet[];
const workspaceSnippets = getWorkspaceConfig().customREPLCommandSnippetsWorkspace as customREPLCommandSnippet[];
const workspaceFolderSnippets = getWorkspaceConfig().customREPLCommandSnippetsWorkspaceFolder as customREPLCommandSnippet[];
const globalSnippets = getConfig().customREPLCommandSnippetsGlobal as customREPLCommandSnippet[];
const workspaceSnippets = getConfig().customREPLCommandSnippetsWorkspace as customREPLCommandSnippet[];
const workspaceFolderSnippets = getConfig().customREPLCommandSnippetsWorkspaceFolder as customREPLCommandSnippet[];
let snippets = [
...(globalSnippets ? globalSnippets : []),
...(workspaceSnippets ? workspaceSnippets : []),
...(workspaceFolderSnippets ? workspaceFolderSnippets : [])];
if (snippets.length < 1) {
snippets = getWorkspaceConfig().customREPLCommandSnippets;
snippets = getConfig().customREPLCommandSnippets;
}
const snippetsDict = {};
const snippetsKeyDict = {};
Expand Down
18 changes: 9 additions & 9 deletions src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as namespace from './namespace';
import * as replHistory from './results-output/repl-history';
import { formatAsLineComments } from './results-output/util';
import { getStateValue } from '../out/cljs-lib/cljs-lib';
import { getWorkspaceConfig } from './config';
import { getConfig } from './config';
import * as replSession from './nrepl/repl-session';
import * as getText from './util/get-text';

Expand Down Expand Up @@ -48,7 +48,7 @@ function addAsComment(c: number, result: string, codeSelection: vscode.Selection
}

async function evaluateCode(code: string, options, selection?: vscode.Selection): Promise<void> {
const pprintOptions = options.pprintOptions || getWorkspaceConfig().prettyPrintingOptions;
const pprintOptions = options.pprintOptions || getConfig().prettyPrintingOptions;
const line = options.line;
const column = options.column;
const filePath = options.filePath;
Expand Down Expand Up @@ -196,44 +196,44 @@ function _currentSelectionElseCurrentForm(editor: vscode.TextEditor): getText.Se
function evaluateSelectionReplace(document = {}, options = {}) {
evaluateSelection(document, Object.assign({}, options, {
replace: true,
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
selectionFn: _currentSelectionElseCurrentForm
})).catch(printWarningForError);
}

function evaluateSelectionAsComment(document = {}, options = {}) {
evaluateSelection(document, Object.assign({}, options, {
comment: true,
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
selectionFn: _currentSelectionElseCurrentForm
})).catch(printWarningForError);
}

function evaluateTopLevelFormAsComment(document = {}, options = {}) {
evaluateSelection(document, Object.assign({}, options, {
comment: true,
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
selectionFn: getText.currentTopLevelFormText
})).catch(printWarningForError);
}

function evaluateTopLevelForm(document = {}, options = {}) {
evaluateSelection(document, Object.assign({}, options, {
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
selectionFn: getText.currentTopLevelFormText
})).catch(printWarningForError);
}

function evaluateCurrentForm(document = {}, options = {}) {
evaluateSelection(document, Object.assign({}, options, {
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
selectionFn: _currentSelectionElseCurrentForm
})).catch(printWarningForError);
}

function evaluateToCursor(document = {}, options = {}) {
evaluateSelection(document, Object.assign({}, options, {
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
selectionFn: (editor: vscode.TextEditor) => {
let [selection, code] = getText.toStartOfList(editor);
return [selection, `(${code})`]
Expand Down Expand Up @@ -351,7 +351,7 @@ async function togglePrettyPrint() {

async function instrumentTopLevelForm() {
evaluateSelection({}, {
pprintOptions: getWorkspaceConfig().prettyPrintingOptions,
pprintOptions: getConfig().prettyPrintingOptions,
debug: true,
selectionFn: getText.currentTopLevelFormText
}).catch(printWarningForError);
Expand Down
10 changes: 5 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function onDidSave(document) {
let {
evaluate,
test,
} = config.getWorkspaceConfig();
} = config.getConfig();

if (document.languageId !== 'clojure') {
return;
Expand All @@ -47,7 +47,7 @@ async function onDidSave(document) {
state.analytics().logEvent("Calva", "OnSaveTest").send();
} else if (evaluate) {
if (!outputWindow.isResultsDoc(document)) {
await eval.loadFile(document, config.getWorkspaceConfig().prettyPrintingOptions);
await eval.loadFile(document, config.getConfig().prettyPrintingOptions);
outputWindow.appendPrompt();
state.analytics().logEvent("Calva", "OnSaveLoad").send();
}
Expand Down Expand Up @@ -92,8 +92,8 @@ async function activate(context: vscode.ExtensionContext) {
const vimExtension = vscode.extensions.getExtension('vscodevim.vim');
const cljKondoExtension = vscode.extensions.getExtension('borkdude.clj-kondo');
const cwConfig = vscode.workspace.getConfiguration('clojureWarrior');
const customCljsRepl = config.getWorkspaceConfig().customCljsRepl;
const replConnectSequences = config.getWorkspaceConfig().replConnectSequences;
const customCljsRepl = config.getConfig().customCljsRepl;
const replConnectSequences = config.getConfig().replConnectSequences;
const BUTTON_GOTO_DOC = "Open the docs";
const BUTTON_OK = "Got it";
const VIM_DOC_URL = "https://calva.io/vim/";
Expand Down Expand Up @@ -162,7 +162,7 @@ async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('calva.switchCljsBuild', connector.switchCljsBuild));
context.subscriptions.push(vscode.commands.registerCommand('calva.selectCurrentForm', select.selectCurrentForm));
context.subscriptions.push(vscode.commands.registerCommand('calva.loadFile', async () => {
await eval.loadFile({}, config.getWorkspaceConfig().prettyPrintingOptions);
await eval.loadFile({}, config.getConfig().prettyPrintingOptions);
outputWindow.appendPrompt();
}));
context.subscriptions.push(vscode.commands.registerCommand('calva.interruptAllEvaluations', eval.interruptAllEvaluations));
Expand Down
8 changes: 4 additions & 4 deletions src/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import { LanguageClient, ServerOptions, LanguageClientOptions, DocumentSymbol, Position } from 'vscode-languageclient';
import * as path from 'path';
import * as util from './utilities'
import { REPL_FILE_EXT, getWorkspaceConfig } from './config';
import { REPL_FILE_EXT, getConfig } from './config';
import { provideClojureDefinition } from './providers/definition';
import { setStateValue, getStateValue } from '../out/cljs-lib/cljs-lib';

Expand All @@ -29,7 +29,7 @@ function createClient(jarPath: string): LanguageClient {
},
middleware: {
handleDiagnostics(uri, diagnostics, next) {
if (!getWorkspaceConfig().displayDiagnostics) {
if (!getConfig().displayDiagnostics) {
return next(uri, []);
}
if (uri.path.endsWith(REPL_FILE_EXT)) {
Expand All @@ -41,13 +41,13 @@ function createClient(jarPath: string): LanguageClient {
return next(document, range, context, token);
},
provideCodeLenses: async (document, token, next): Promise<vscode.CodeLens[]> => {
if (getWorkspaceConfig().referencesCodeLensEnabled) {
if (getConfig().referencesCodeLensEnabled) {
return await next(document, token);
}
return [];
},
resolveCodeLens: async (codeLens, token, next) => {
if (getWorkspaceConfig().referencesCodeLensEnabled) {
if (getConfig().referencesCodeLensEnabled) {
return await next(codeLens, token);
}
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/nrepl/connectSequence.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from "vscode";
import * as state from "../state";
import * as utilities from '../utilities';
import { getWorkspaceConfig } from '../config';
import { getConfig } from '../config';

enum ProjectTypes {
"Leiningen" = "Leiningen",
Expand Down Expand Up @@ -181,7 +181,7 @@ const defaultCljsTypes: { [id: string]: CljsTypeConfig } = {

/** Retrieve the replConnectSequences from the config */
function getCustomConnectSequences(): ReplConnectSequence[] {
let sequences: ReplConnectSequence[] = getWorkspaceConfig().replConnectSequences;
let sequences: ReplConnectSequence[] = getConfig().replConnectSequences;

for (let sequence of sequences) {
if (sequence.name == undefined ||
Expand Down Expand Up @@ -218,7 +218,7 @@ function getConnectSequences(projectTypes: string[]): ReplConnectSequence[] {
*/
function getDefaultCljsType(cljsType: string): CljsTypeConfig {
// TODO: Find a less hacky way to get dynamic config for lein-figwheel
defaultCljsTypes["lein-figwheel"].shouldOpenUrl = getWorkspaceConfig().openBrowserWhenFigwheelStarted;
defaultCljsTypes["lein-figwheel"].shouldOpenUrl = getConfig().openBrowserWhenFigwheelStarted;
return defaultCljsTypes[cljsType];
}

Expand Down
4 changes: 2 additions & 2 deletions src/nrepl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as outputWindow from '../results-output/results-doc';
import { formatAsLineComments } from '../results-output/util';
import type { ReplSessionType } from '../config';
import { getStateValue, prettyPrint } from '../../out/cljs-lib/cljs-lib';
import { getWorkspaceConfig } from '../config';
import { getConfig } from '../config';

/** An nREPL client */
export class NReplClient {
Expand Down Expand Up @@ -360,7 +360,7 @@ export class NReplSession {
complete(ns: string, symbol: string, context?: string) {
return new Promise<any>((resolve, reject) => {
const id = this.client.nextId,
extraOpts = getWorkspaceConfig().enableJSCompletions ? { "enhanced-cljs-completion?": "t" } : {};
extraOpts = getConfig().enableJSCompletions ? { "enhanced-cljs-completion?": "t" } : {};
this.messageHandlers[id] = (msg) => {
resolve(msg);
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as projectTypes from './project-types';
import * as outputWindow from '../results-output/results-doc';
import { JackInTerminal, JackInTerminalOptions, createCommandLine } from "./jack-in-terminal";
import * as liveShareSupport from '../liveShareSupport';
import { getWorkspaceConfig } from '../config';
import { getConfig } from '../config';

let jackInPTY: JackInTerminal = undefined;
let jackInTerminal: vscode.Terminal = undefined;
Expand All @@ -35,7 +35,7 @@ function resolveEnvVariables(entry: any): any {
function getJackInEnv(): any {
return {
...process.env,
..._.mapValues(getWorkspaceConfig().jackInEnv as object, resolveEnvVariables)
..._.mapValues(getConfig().jackInEnv as object, resolveEnvVariables)
};
}

Expand Down Expand Up @@ -68,7 +68,7 @@ async function executeJackInTask(terminalOptions: JackInTerminalOptions, connect
cancelJackInTask();
});
jackInTerminal = (<any>vscode.window).createTerminal({ name: `Calva Jack-in: ${connectSequence.name}`, pty: jackInPTY });
if (getWorkspaceConfig().autoOpenJackInTerminal) {
if (getConfig().autoOpenJackInTerminal) {
jackInTerminal.show();
}
jackInPTY.onDidClose((e) => {
Expand Down
12 changes: 6 additions & 6 deletions src/nrepl/project-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as utilities from '../utilities';
import * as pprint from '../printer';
import { getWorkspaceConfig } from '../config';
import { getConfig } from '../config';
import { keywordize, unKeywordize } from '../util/string';
import { CljsTypes, ReplConnectSequence } from './connectSequence';
const { parseForms, parseEdn } = require('../../out/cljs-lib/cljs-lib');
Expand Down Expand Up @@ -160,7 +160,7 @@ async function leinProfilesAndAlias(defproject: any, connectSequence: ReplConnec
profiles = launchProfiles.map(keywordize);
} else {
let projectProfiles = profilesIndex > -1 ? Object.keys(defproject[profilesIndex + 1]) : [];
const myProfiles = getWorkspaceConfig().myLeinProfiles;
const myProfiles = getConfig().myLeinProfiles;
if (myProfiles && myProfiles.length) {
projectProfiles = [...projectProfiles, ...myProfiles];
}
Expand All @@ -185,9 +185,9 @@ export enum JackInDependency {
"cider/piggieback" = "cider/piggieback"
}

const NREPL_VERSION = () => getWorkspaceConfig().jackInDependencyVersions["nrepl"],
CIDER_NREPL_VERSION = () => getWorkspaceConfig().jackInDependencyVersions["cider-nrepl"],
PIGGIEBACK_VERSION = () => getWorkspaceConfig().jackInDependencyVersions["cider/piggieback"];
const NREPL_VERSION = () => getConfig().jackInDependencyVersions["nrepl"],
CIDER_NREPL_VERSION = () => getConfig().jackInDependencyVersions["cider-nrepl"],
PIGGIEBACK_VERSION = () => getConfig().jackInDependencyVersions["cider/piggieback"];

const cliDependencies = () => {
return {
Expand Down Expand Up @@ -400,7 +400,7 @@ async function cljCommandLine(connectSequence: ReplConnectSequence, cljsType: Cl
aliases = launchAliases.map(keywordize);
} else {
let projectAliases = parsed && parsed.aliases != undefined ? Object.keys(parsed.aliases) : [];
const myAliases = getWorkspaceConfig().myCljAliases;
const myAliases = getConfig().myCljAliases;
if (myAliases && myAliases.length) {
projectAliases = [...projectAliases, ...myAliases];
}
Expand Down
4 changes: 2 additions & 2 deletions src/nrepl/repl-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as utilities from "../utilities";
import * as sequence from "./connectSequence";
import * as jackIn from "./jack-in";
import * as outputWindow from '../results-output/results-doc';
import { getWorkspaceConfig } from '../config';
import { getConfig } from '../config';
import * as replSession from './repl-session';

export const USER_TEMPLATE_FILE_NAMES = ['user.clj'];
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function startStandaloneRepl(context: vscode.ExtensionContext, docN

await jackIn.jackIn(sequence.genericDefaults[0], async () => {
await vscode.window.showTextDocument(mainDoc, { preview: false, viewColumn: vscode.ViewColumn.One, preserveFocus: false });
await eval.loadFile({}, getWorkspaceConfig().prettyPrintingOptions);
await eval.loadFile({}, getConfig().prettyPrintingOptions);
outputWindow.appendPrompt();
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/printer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getWorkspaceConfig } from './config';
import { getConfig } from './config';

export type PrettyPrintingOptions = {
enabled: boolean,
Expand Down Expand Up @@ -58,7 +58,7 @@ export function getServerSidePrinter(pprintOptions: PrettyPrintingOptions) {
}

export function prettyPrintingOptions(): PrettyPrintingOptions {
return getWorkspaceConfig().prettyPrintingOptions;
return getConfig().prettyPrintingOptions;
}

export const zprintDependencies = {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/infoparser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignatureInformation, ParameterInformation, MarkdownString } from 'vscode';
import * as tokenCursor from '../cursor-doc/token-cursor';
import { getWorkspaceConfig } from "../config";
import { getConfig } from "../config";

export class REPLInfoParser {
private _name: string = undefined;
Expand Down Expand Up @@ -223,7 +223,7 @@ export class REPLInfoParser {
if (!this._specialForm && !argList.match(/\?/)) {
signature.parameters = this.getParameters(symbol, argList);
}
if (this._docString && getWorkspaceConfig().showDocstringInParameterHelp) {
if (this._docString && getConfig().showDocstringInParameterHelp) {
signature.documentation = this.formatDocString(this._docString);
}
return signature;
Expand Down
2 changes: 1 addition & 1 deletion src/results-output/results-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function initResultsDoc(): Promise<vscode.TextDocument> {
await vscode.workspace.applyEdit(edit);
resultsDoc.save();

if (config.getWorkspaceConfig().autoOpenREPLWindow) {
if (config.getConfig().autoOpenREPLWindow) {
const resultsEditor = await vscode.window.showTextDocument(resultsDoc, getViewColumn(), true);
const firstPos = resultsEditor.document.positionAt(0);
const lastPos = resultsDoc.positionAt(Infinity);
Expand Down
4 changes: 2 additions & 2 deletions src/status.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import statusbar from './statusbar';
import * as state from './state';
import { getWorkspaceConfig } from './config';
import { getConfig } from './config';
import { updateReplSessionType } from './nrepl/repl-session';

function updateNeedReplUi(isNeeded: boolean, context = state.extensionContext) {
Expand All @@ -10,7 +10,7 @@ function updateNeedReplUi(isNeeded: boolean, context = state.extensionContext) {
}

function shouldshowReplUi(context = state.extensionContext): boolean {
return context.workspaceState.get('needReplUi') || !getWorkspaceConfig().hideReplUi;
return context.workspaceState.get('needReplUi') || !getConfig().hideReplUi;
}

function update(context = state.extensionContext) {
Expand Down
Loading

0 comments on commit 2a20e8e

Please sign in to comment.