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

[WIP] custom repl connect sequence #285

Merged
merged 135 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
0e8d21f
Add first Version for default start sequences
Aug 15, 2019
a3c6047
Add replConnectSequences config definition
Aug 15, 2019
1133dc3
Moving required block to right position
Aug 15, 2019
09865bb
Add more and better description based on the issue description
Aug 15, 2019
fb79404
How much description can the user handle?
PEZ Aug 15, 2019
4ce03aa
Less duh!, I think :smile:
PEZ Aug 15, 2019
3aded20
Add function to get connectSequences
Aug 16, 2019
b90d162
Add missing type return for getConnectSequences
Aug 16, 2019
0b000e6
ConnectSequences for multiple projectTypes, fixing enum values
Aug 18, 2019
d3e016c
Use ConnectSequences for user selection, need to use it and pass it t…
Aug 18, 2019
71cd685
Passing ConnectSequence to executeJackIn + some formating
Aug 18, 2019
8370a16
Build-in cljs-types translated
Aug 19, 2019
952f89c
Add myLeinProfiles settings for jack-in
PEZ Aug 19, 2019
510bd25
First version for translating CustomCljsType to ReplType description
Aug 19, 2019
49fd7bf
Add support for myCljAliases
PEZ Aug 19, 2019
fc66ed9
npm i
PEZ Aug 20, 2019
d35b099
camelCasing it properly
PEZ Aug 20, 2019
309d1b0
Simplify menu creation some
PEZ Aug 20, 2019
d2ada69
v2.0.32 support launching with aliases
PEZ Aug 17, 2019
39e47e0
Use `cider/cider-nrepl` `0.22.0-beta10`
PEZ Aug 16, 2019
f2dbf45
Make let readable
PEZ Aug 16, 2019
42d3726
Prepare to figure out __prefix__
PEZ Aug 16, 2019
7515918
Extract `context` for cider-nrepl `complete`
PEZ Aug 17, 2019
199f8de
Handle non-closed top level forms
PEZ Aug 17, 2019
45bb213
Don't pass any context when we don't have it
PEZ Aug 17, 2019
64a4afa
Revert back to stable cider-nrepl
PEZ Aug 17, 2019
fe4f744
Explain a bit what `forwardList` is used for
PEZ Aug 18, 2019
c1e0d45
Add nodemon and webpack-dev-server
PEZ Aug 18, 2019
3b2eef4
Move the rest of the repl-interactor code in here
PEZ Aug 18, 2019
de66f0c
Move webview-src insidce calva rootDir
PEZ Aug 18, 2019
7e1ee94
Add withinValidList() to TokenCursor
PEZ Aug 18, 2019
5f7403f
Disable sync diagnostics
PEZ Aug 18, 2019
f13939b
Clarify the trimming and keywordizing of aliases
PEZ Aug 20, 2019
3dae919
ConnectSequence are used now to start everything, adding name to cust…
Aug 20, 2019
1702b0e
CHeck if result and out are not undefined before using
Aug 21, 2019
559c442
Fixing: ProjectType for cli
Aug 21, 2019
cf7bdf0
Fix empty builds check and build quoting
PEZ Aug 22, 2019
02ed62c
Check if cljsType is set before using it, always add build-in to cust…
Aug 23, 2019
489d370
Check if name and projectType is set in customSequences, if not infor…
Aug 23, 2019
9cd7905
Removed while loop to wait, need to find a way
Aug 23, 2019
7c4ddd0
Show all output/error message and result from the jackInCode in calva…
Aug 23, 2019
99a23fb
Made afterCLJReplJackInCode to string onld
Aug 23, 2019
93f6dfd
StripAnsi from afterCLJReplJackInCode + better output, fixing lein-fi…
Aug 23, 2019
ec0117b
Evaluate afterCLJJackIn in REPL window
PEZ Aug 23, 2019
1b9d99a
Add deprectationMessage to customCLjsRepl
PEZ Aug 23, 2019
7f8755e
Fix schema specifying the wrong CLI key
PEZ Aug 23, 2019
71345cc
Trying to better understand what's going on =)
PEZ Aug 23, 2019
be934d5
Use literal regexps instead of strings
PEZ Aug 24, 2019
629a3f7
Use same regexp for searching out and err
PEZ Aug 24, 2019
27132f2
Add printer for `printThisLineRegExp`
PEZ Aug 24, 2019
00e8ea7
Merge branch 'master' into wip/custom-repl-connect-sequence
PEZ Aug 24, 2019
3c63fcf
Print matching lines as they come in
PEZ Aug 25, 2019
bdea802
This file shouldn't have been commited!
PEZ Aug 25, 2019
6d45763
When ready to connect, instruct user to start app
PEZ Aug 25, 2019
5f0eec5
Add help for starting CLJS app
PEZ Aug 25, 2019
69f62db
Search for connectedRegExp in result as well
PEZ Aug 25, 2019
ef2a0bc
When no is-started-regexp return true after eval
PEZ Aug 25, 2019
2c0c576
Use outputProcessors also for BUILDS case
PEZ Aug 25, 2019
af0daf2
Rename some symbols and read config from `state`
PEZ Aug 26, 2019
99e3a62
Read figwheel openURL config at connect time
PEZ Aug 26, 2019
b15ee77
Make room for breakpoints :smile:
PEZ Aug 26, 2019
2ee901c
Changed openURL extraction to named group
PEZ Aug 26, 2019
25db46e
Covering more Figwheel Main output scenarios
PEZ Aug 26, 2019
384bffc
Document the outputprocessors some
PEZ Aug 26, 2019
2ca3418
Clarify that figwheel openURL config is deferred
PEZ Aug 27, 2019
42833f2
Jack-in start and done messaging
PEZ Aug 28, 2019
c2d8d93
Separate dependencies for legacy figwheel and main
PEZ Aug 28, 2019
23b960f
Merge branch 'master' into wip/custom-repl-connect-sequence
PEZ Aug 28, 2019
5be340b
baseType -> dependsOn
PEZ Aug 29, 2019
49bb1c2
Use cljsTypeName much sparser
PEZ Aug 30, 2019
05a9c08
Moved project types to project-types.ts
PEZ Aug 30, 2019
706c0fb
Re-enabled standalone connect
PEZ Aug 30, 2019
06a98d6
Guard against no sane sequence selected
PEZ Aug 30, 2019
7db5c5c
Stop using init-the-get for ws folder
PEZ Aug 30, 2019
ad0c3d8
Get the cljs name a bit more robustly
PEZ Aug 30, 2019
bbeac27
Import lodash using `* as` (or bust)
PEZ Aug 30, 2019
805d969
Don't use lodash for mapping over shadow builds
PEZ Aug 30, 2019
7ad477b
Abort shadow-cljs jack-in if no build selected
PEZ Aug 30, 2019
108cb89
Re-enable build-switching functionality
PEZ Aug 31, 2019
a7b0757
Use => syntax in main connector.ts export
PEZ Aug 31, 2019
ac65db4
Make repl window follow when nrepl session changes
PEZ Aug 31, 2019
c41cd92
Don't recreate the repl type on build switch
PEZ Aug 31, 2019
b81886a
Rename recreate cljs repl to Switch build
PEZ Sep 1, 2019
5025348
Always inject piggieback on cljs jack-in
PEZ Sep 1, 2019
3340a78
Add Nashorn built-in cjls type
PEZ Sep 1, 2019
dc16ffb
Clarify error message some
PEZ Sep 1, 2019
ddab0a5
Deal with nreplPortFile in project-types.ts
PEZ Sep 1, 2019
c86a910
Rename go use builds for FM as well
PEZ Sep 1, 2019
8d137a2
More to the point connection messaging
PEZ Sep 2, 2019
cd67fe0
Introduced isStarted for cljsTypes
PEZ Sep 2, 2019
964c01d
Add isStarted to custom sequence config
PEZ Sep 2, 2019
3d2ae3e
Use closure local for managing started state
PEZ Sep 2, 2019
d32947b
Merge remote-tracking branch 'origin/wip/my-aliases' into wip/custom-…
PEZ Sep 2, 2019
c1e0dd2
Move myAliases/-Profiles into the connect sequence
PEZ Sep 2, 2019
3168b68
Introduce launchProfiles
Sep 3, 2019
3787417
Introduce menuSelections settings for sequences
PEZ Sep 3, 2019
70208a9
Reinstall myCljAliases and myLeinProfiles
PEZ Sep 3, 2019
ddd3dde
Listen to some linter suggestions
PEZ Sep 3, 2019
d856212
When Custom Sequence is set changed behavior
Sep 3, 2019
ddcdb33
Update launch builds description
PEZ Sep 3, 2019
f7a27ff
Remove `builds` from sequence cljs type schema
PEZ Sep 3, 2019
332282b
Merge branch 'master' into wip/custom-repl-connect-sequence
PEZ Sep 4, 2019
ee1f2e2
Remove CLJS task and make TS task build CLJS first
PEZ Sep 4, 2019
7864449
Menu sel leinProfiles, leinAlias, cljAliases
PEZ Sep 4, 2019
5c5109d
Switching only to builds that have been started
PEZ Sep 5, 2019
34b0e33
Don't show build select if only one build
PEZ Sep 5, 2019
23f8c82
Init circleci config
Sep 4, 2019
f185fcd
Add workflow and a publish job
Sep 4, 2019
74dba7f
Add command for running tests
PEZ Sep 4, 2019
5f5874d
Extract Version to file that gets saved to the cache
Sep 5, 2019
b597fc8
Other version extraction and some formating issues
Sep 5, 2019
0064e24
Typo fixed other errors
Sep 5, 2019
cacaf9f
Remvod vsce in test job, also install vsce as sudo
Sep 5, 2019
2b96791
Compile tests (which also runs them)
PEZ Sep 5, 2019
7c4c563
Add context to publish, remvo filters for build
Sep 5, 2019
73127bf
Trying w/o quotes for version extract command
PEZ Sep 5, 2019
aba76a1
Change to publishing from `release` branch
PEZ Sep 5, 2019
0155207
Add approval job to workflow
Sep 5, 2019
0ddb414
Using workspace instead of cache to get vsix to next job
Sep 5, 2019
aa60ba0
Using cache for node-modules
Sep 5, 2019
9aca833
Find out version number the same way in publish
PEZ Sep 5, 2019
6e13164
Checkout calva in publish step
PEZ Sep 5, 2019
594380e
Need working directory too
PEZ Sep 5, 2019
291fe26
Pick up version JIT
PEZ Sep 5, 2019
b592d68
Cache maven deps
PEZ Sep 5, 2019
15e505f
Typo: Restoring more than just node-modules
PEZ Sep 5, 2019
e6e9cc9
Save the cache after running shadow-cljs
PEZ Sep 5, 2019
0763213
Append commit-sha to vsix version if not release
PEZ Sep 5, 2019
3e8f5e0
Update jack-in info in README
PEZ Sep 6, 2019
558602a
Bump version and add branch name and sha
PEZ Sep 6, 2019
ce2e26c
Merge branch 'master' into wip/custom-repl-connect-sequence
PEZ Sep 6, 2019
b30eeb8
Use `npx version` instead of `semver`
PEZ Sep 6, 2019
4f2c4a5
Merge branch 'master' into wip/custom-repl-connect-sequence
PEZ Sep 7, 2019
b603a86
Merge branch 'dev' into wip/custom-repl-connect-sequence
PEZ Sep 8, 2019
8792488
Add errorMessage at start if old cljsRepl settings
PEZ Sep 10, 2019
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
598 changes: 265 additions & 333 deletions calva/connector.ts

Large diffs are not rendered by default.

38 changes: 30 additions & 8 deletions calva/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import * as replWindow from "./repl-window";
import { format } from 'url';
import * as greetings from "./greet";
import Analytics from './analytics';
import * as open from 'open';

import { edit } from './paredit/utils';

function onDidSave(document) {
Expand Down Expand Up @@ -63,10 +65,28 @@ function onDidOpen(document) {
function activate(context: vscode.ExtensionContext) {
state.cursor.set('analytics', new Analytics(context));
state.analytics().logPath("/start").logEvent("LifeCycle", "Started").send();

const chan = state.outputChannel();


let legacyExtension = vscode.extensions.getExtension('cospaia.clojure4vscode'),
const legacyExtension = vscode.extensions.getExtension('cospaia.clojure4vscode'),
fmtExtension = vscode.extensions.getExtension('cospaia.calva-fmt'),
pareEditExtension = vscode.extensions.getExtension('cospaia.paredit-revived');
pareEditExtension = vscode.extensions.getExtension('cospaia.paredit-revived'),
customCljsRepl = state.config().customCljsRepl,
replConnectSequences = state.config().replConnectSequences,
BUTTON_GOTO_WIKI = "Open the Wiki",
BUTTON_OK = "Got it",
WIKI_URL = "https://github.com/BetterThanTomorrow/calva/wiki/Custom-Connect-Sequences";

if (customCljsRepl && replConnectSequences.length == 0) {
chan.appendLine("Old customCljsRepl settings detected.");
vscode.window.showErrorMessage("Old customCljsRepl settings detected. You need to specifiy it using the new calva.customConnectSequence setting. See the Calva wiki for instructions.", ...[BUTTON_GOTO_WIKI, BUTTON_OK])
.then(v => {
if (v == BUTTON_GOTO_WIKI) {
open(WIKI_URL);
}
})
}

if (legacyExtension) {
vscode.window.showErrorMessage("Calva Legacy extension detected. Things will break. Please uninstall, or disable, the old Calva extension.", ...["Roger that. Right away!"])
Expand All @@ -87,7 +107,6 @@ function activate(context: vscode.ExtensionContext) {

replWindow.activate(context);

let chan = state.outputChannel();
chan.appendLine("Calva activated.");
let {
lint,
Expand All @@ -109,9 +128,9 @@ function activate(context: vscode.ExtensionContext) {
})
}));
context.subscriptions.push(vscode.commands.registerCommand('calva.jackIn', jackIn.calvaJackIn))
context.subscriptions.push(vscode.commands.registerCommand('calva.connect', connector.connect));
context.subscriptions.push(vscode.commands.registerCommand('calva.connect', connector.connectCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.toggleCLJCSession', connector.toggleCLJCSession));
context.subscriptions.push(vscode.commands.registerCommand('calva.recreateCljsRepl', connector.recreateCljsRepl));
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', () => {
EvaluateMiddleWare.loadFile();
Expand Down Expand Up @@ -174,9 +193,12 @@ function activate(context: vscode.ExtensionContext) {
vscode.commands.executeCommand("setContext", "calva:pareditValid", false);
}
status.update();
if (editor && editor.document && editor.document.fileName.match(/\.clj[cs]?/).length && state.config().syncReplNamespaceToCurrentFile) {
replWindow.setREPLNamespace(util.getDocumentNamespace(editor.document))
.catch(reasons => { console.warn(`Namespace sync failed, becauase: ${reasons}`) });
if (editor && editor.document && editor.document.fileName) {
const fileExtIfClj = editor.document.fileName.match(/\.clj[cs]?/);
if (fileExtIfClj && fileExtIfClj.length && state.config().syncReplNamespaceToCurrentFile) {
replWindow.setREPLNamespace(util.getDocumentNamespace(editor.document))
.catch(reasons => { console.warn(`Namespace sync failed, becauase: ${reasons}`) });
}
}
}));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(annotations.onDidChangeTextDocument))
Expand Down
229 changes: 229 additions & 0 deletions calva/nrepl/connectSequence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import * as vscode from "vscode";
import * as state from "../state";
import * as projectTypes from './project-types';
import * as utilities from '../utilities';

enum ProjectTypes {
"Leiningen" = "Leiningen",
"Clojure CLI" = "Clojure CLI",
"shadow-cljs" = "shadow-cljs"
}

enum CljsTypes {
"Figwheel Main" = "Figwheel Main",
"lein-figwheel" = "lein-figwheel",
"shadow-cljs" = "shadow-cljs",
"Nashorn" = "Nashorn",
"User provided" = "User provided"
}

interface CljsTypeConfig {
name: string,
dependsOn?: CljsTypes,
isStarted: boolean,
startCode?: string,
buildsRequired?: boolean,
isReadyToStartRegExp?: string | RegExp,
openUrlRegExp?: string | RegExp,
shouldOpenUrl?: boolean,
connectCode: string | Object,
isConnectedRegExp?: string | RegExp,
printThisLineRegExp?: string | RegExp
}

interface MenuSelecions {
leinProfiles?: string[],
leinAlias?: string,
cljAliases?: string[],
cljsLaunchBuilds?: string[],
cljsDefaultBuild?: string
}

interface ReplConnectSequence {
name: string,
projectType: ProjectTypes,
afterCLJReplJackInCode?: string,
cljsType?: CljsTypes | CljsTypeConfig,
menuSelections?: MenuSelecions,
}

const leiningenDefaults: ReplConnectSequence[] =
[{
name: "Leiningen",
projectType: ProjectTypes.Leiningen
},
{
name: "Leiningen + Figwheel",
projectType: ProjectTypes.Leiningen,
cljsType: CljsTypes["lein-figwheel"]
},
{
name: "Leiningen + Figwheel Main",
projectType: ProjectTypes.Leiningen,
cljsType: CljsTypes["Figwheel Main"]
},
{
name: "Leiningen + Nashorn",
projectType: ProjectTypes.Leiningen,
cljsType: CljsTypes["Nashorn"]
}];

const cljDefaults: ReplConnectSequence[] =
[{
name: "Clojure CLI",
projectType: ProjectTypes["Clojure CLI"]
},
{
name: "Clojure CLI + Figwheel",
projectType: ProjectTypes["Clojure CLI"],
cljsType: CljsTypes["lein-figwheel"]
},
{
name: "Clojure CLI + Figwheel Main",
projectType: ProjectTypes["Clojure CLI"],
cljsType: CljsTypes["Figwheel Main"]
},
{
name: "Clojure CLI + Nashorn",
projectType: ProjectTypes["Clojure CLI"],
cljsType: CljsTypes["Nashorn"]
}];

const shadowCljsDefaults: ReplConnectSequence[] = [{
name: "shadow-cljs",
projectType: ProjectTypes["shadow-cljs"],
cljsType: CljsTypes["shadow-cljs"]
}]

const defaultSequences = {
"lein": leiningenDefaults,
"clj": cljDefaults,
"shadow-cljs": shadowCljsDefaults
};

const defaultCljsTypes: { [id: string]: CljsTypeConfig } = {
"Figwheel Main": {
name: "Figwheel Main",
buildsRequired: true,
isStarted: false,
startCode: `(do (require 'figwheel.main.api) (figwheel.main.api/start %BUILDS%))`,
isReadyToStartRegExp: /Prompt will show|Open(ing)? URL|already running/,
openUrlRegExp: /(Starting Server at|Open(ing)? URL) (?<url>\S+)/,
shouldOpenUrl: false,
connectCode: `(do (use 'figwheel.main.api) (figwheel.main.api/cljs-repl %BUILD%))`,
isConnectedRegExp: /To quit, type: :cljs\/quit/
},
"lein-figwheel": {
name: "lein-figwheel",
buildsRequired: false,
isStarted: false,
isReadyToStartRegExp: /Launching ClojureScript REPL for build/,
openUrlRegExp: /Figwheel: Starting server at (?<url>\S+)/,
// shouldOpenUrl: will be set at use-time of this config,
connectCode: "(do (use 'figwheel-sidecar.repl-api) (if (not (figwheel-sidecar.repl-api/figwheel-running?)) (figwheel-sidecar.repl-api/start-figwheel!)) (figwheel-sidecar.repl-api/cljs-repl))",
isConnectedRegExp: /To quit, type: :cljs\/quit/
},
"shadow-cljs": {
name: "shadow-cljs",
buildsRequired: true,
isStarted: true,
// isReadyToStartRegExp: /To quit, type: :cljs\/quit/,
connectCode: {
build: `(shadow.cljs.devtools.api/nrepl-select %BUILD%)`,
repl: `(shadow.cljs.devtools.api/%REPL%)`
},
shouldOpenUrl: false,
isConnectedRegExp: /:selected/
},
"Nashorn": {
name: "Nashorn",
buildsRequired: false,
isStarted: true,
connectCode: "(do (require 'cljs.repl.nashorn) (cider.piggieback/cljs-repl (cljs.repl.nashorn/repl-env)))",
isConnectedRegExp: "To quit, type: :cljs/quit"
}
};

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

for (let sequence of sequences) {
if (sequence.name == undefined ||
sequence.projectType == undefined) {

vscode.window.showWarningMessage("Check your calva.replConnectSequences. " +
"You need to supply name and projectType for every sequence. " +
"After fixing the customSequences can be used.");

return [];
}
}

return sequences;
}

/**
* Retrieve the replConnectSequences and returns only that if only one was defined.
* Otherwise the user defined will be combined with the defaults one to be returned.
* @param projectType what default Sequences would be used (leiningen, clj, shadow-cljs)
*/
function getConnectSequences(projectTypes: string[]): ReplConnectSequence[] {
let customSequences = getCustomConnectSequences();

if (customSequences.length) {
return customSequences;
} else {
let result = [];
for (let pType of projectTypes) {
result = result.concat(defaultSequences[pType]);
}
return result;
}
}

/**
* Returns the CLJS-Type description of one of the build-in.
* @param cljsType Build-in cljsType
*/
function getDefaultCljsType(cljsType: string): CljsTypeConfig {
// TODO: Find a less hacky way to get dynamic config for lein-figwheel
defaultCljsTypes["lein-figwheel"].shouldOpenUrl = state.config().openBrowserWhenFigwheelStarted;
return defaultCljsTypes[cljsType];
}

async function askForConnectSequence(cljTypes: string[], saveAs: string, logLabel: string): Promise<ReplConnectSequence> {
// figure out what possible kinds of project we're in
if (cljTypes.length == 0) {
vscode.window.showErrorMessage("Cannot find project, no project.clj, deps.edn or shadow-cljs.edn.");
state.analytics().logEvent("REPL", logLabel, "FailedFindingProjectType").send();
return;
}

const sequences = getConnectSequences(cljTypes);
if (sequences.length > 1) {
const projectConnectSequenceName = await utilities.quickPickSingle({
values: sequences.map(s => { return s.name }),
placeHolder: "Please select a project type",
saveAs: `${state.getProjectRoot()}/${saveAs}`,
autoSelect: true
});
if (!projectConnectSequenceName) {
state.analytics().logEvent("REPL", logLabel, "NoProjectTypePicked").send();
return;
}

return sequences.find(seq => seq.name === projectConnectSequenceName);
} else {
return sequences[0];
}
}

export {
askForConnectSequence,
getConnectSequences,
getDefaultCljsType,
CljsTypes,
ReplConnectSequence,
CljsTypeConfig
}
Loading