Skip to content

Commit

Permalink
Merge pull request #138 from andresrgz/wsl-enhancements
Browse files Browse the repository at this point in the history
Enhancements for WSL support
  • Loading branch information
PEZ authored Mar 3, 2019
2 parents e911000 + d9d6157 commit 61e6a0d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
7 changes: 4 additions & 3 deletions calva/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import terminal from './terminal';
import CalvaCompletionItemProvider from './providers/completion';
import TextDocumentContentProvider from './providers/content';
import HoverProvider from './providers/hover';
import DefinitionProvider from './providers/definition';
import { DefinitionProvider, WslDefinitionProvider } from './providers/definition';
import EvaluateMiddleWare from './repl/middleware/evaluate';
import LintMiddleWare from './repl/middleware/lint';
import TestRunnerMiddleWare from './repl/middleware/testRunner';
Expand Down Expand Up @@ -60,7 +60,8 @@ function activate(context) {
chan.appendLine("Calva activated.");
let {
autoConnect,
lint
lint,
useWSL
} = state.config();

status.update();
Expand Down Expand Up @@ -125,7 +126,7 @@ function activate(context) {
// PROVIDERS
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(state.mode, new CalvaCompletionItemProvider()));
context.subscriptions.push(vscode.languages.registerHoverProvider(state.mode, new HoverProvider()));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(state.mode, new DefinitionProvider()));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(state.mode, useWSL ? new WslDefinitionProvider() : new DefinitionProvider()));

vscode.workspace.registerTextDocumentContentProvider('jar', new TextDocumentContentProvider());

Expand Down
61 changes: 40 additions & 21 deletions calva/providers/definition.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
import * as vscode from 'vscode';
import * as state from '../state';
import * as util from '../utilities';
export default class DefinitionProvider implements vscode.DefinitionProvider {
state: any;
constructor() {
this.state = state;
}

async provideDefinition(document, position, token) {
let text = util.getWordAtPosition(document, position);
let client = util.getSession(util.getFileType(document));
if(this.state.deref().get('connected')) {
let info = await client.info(util.getNamespace(document.getText()), text);
if(info.file && info.file.length > 0) {
let pos = new vscode.Position(info.line - 1, info.column);
return new vscode.Location(vscode.Uri.parse(info.file), pos);
}
}
}
};
import * as vscode from 'vscode';
import * as state from '../state';
import * as util from '../utilities';
import { wslToWindows } from 'wsl-path';

export class DefinitionProvider implements vscode.DefinitionProvider {
state: any;
constructor() {
this.state = state;
}

async provideDefinition(document, position, token) {
let text = util.getWordAtPosition(document, position);
let client = util.getSession(util.getFileType(document));
if(this.state.deref().get('connected')) {
let info = await client.info(util.getNamespace(document.getText()), text);
if(info.file && info.file.length > 0) {
let pos = new vscode.Position(info.line - 1, info.column);
return new vscode.Location(vscode.Uri.parse(info.file), pos);
}
}
}
};

export class WslDefinitionProvider extends DefinitionProvider {
async provideDefinition(document, position, token) {
const location = await super.provideDefinition(document, position, token);
if (!location) return;

if (location.uri.scheme === 'jar') {
const path = vscode.Uri.parse(location.uri.path).path;
const windowsFilePath = await wslToWindows(path);
const windowsFileUri = vscode.Uri.file(windowsFilePath);
return new vscode.Location(location.uri.with({ path: `file:${windowsFileUri.path}`}), location.range);
}

const windowsFilePath = await wslToWindows(location.uri.path);
return new vscode.Location(vscode.Uri.file(windowsFilePath), location.range);
}
}
8 changes: 5 additions & 3 deletions calva/repl/middleware/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spawn } from 'child_process';
import * as path from 'path';
import * as state from '../../state';
import * as util from '../../utilities';
import { windowsToWslSync } from 'wsl-path';

function parseJokerLine(jokerOutput) {
const OUTPUT_REGEXP = /.+:([0-9]+)+:([0-9]+): (.+)/,
Expand Down Expand Up @@ -42,9 +43,10 @@ function buildJokerPath(jokerPath, join) {
}

function jokerChildProcess(fileName) {
let { jokerPath, useJokerOnWSL } = state.config();
if (useJokerOnWSL) {
return spawn("wsl", [buildJokerPath(jokerPath, path.posix.join), "--lint", `\$(wslpath '${fileName}')`]);
let { jokerPath, useWSL } = state.config();
if (useWSL) {
const wslFilePath = windowsToWslSync(fileName);
return spawn("wsl", [buildJokerPath(jokerPath, path.posix.join), "--lint", wslFilePath]);
}
return spawn(buildJokerPath(jokerPath, path.join), ["--lint", fileName]);
}
Expand Down
2 changes: 1 addition & 1 deletion calva/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function config() {
connectREPLCommand: configOptions.get("connectREPLCommand"),
projectRootDirectory: projectRootDirectoryConfig.replace(/^\/|\/$/g, ""),
jokerPath: configOptions.get("jokerPath"),
useJokerOnWSL: configOptions.get("useJokerOnWSL"),
useWSL: configOptions.get("useWSL"),
syncReplNamespaceToCurrentFile: configOptions.get("syncReplNamespaceToCurrentFile")
};
}
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@
"calva.jokerPath": {
"type": "string",
"default": "joker",
"description": "Sets the path in which the Joker executable can be found"
"description": "Sets the path in which the Joker executable can be found. If useWSL has been set to true, this should be a valid WSL path."
},
"calva.useJokerOnWSL": {
"calva.useWSL": {
"type": "boolean",
"default": false,
"description": "Specifies if Joker will run through WSL"
"description": "Specifies if the nREPL and Joker are running within WSL."
}
}
},
Expand Down Expand Up @@ -355,7 +355,8 @@
"net": "1.0.2",
"npm": "^6.4.0",
"paredit.js": "^0.3.4",
"vscode-extension-telemetry": "0.0.15"
"vscode-extension-telemetry": "0.0.15",
"wsl-path": "^1.1.0"
},
"devDependencies": {
"@calva/repl-interactor": "0.0.1",
Expand Down

0 comments on commit 61e6a0d

Please sign in to comment.