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

Add WSL Idris installation compatibility #263

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion lib/idris-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {
Pane,
WorkspaceOpenOptions,
} from 'atom'
import { windowsToWsl } from 'wsl-path'

export class IdrisController {
errorMarkers: Array<DisplayMarker> = []
model: IdrisModel = new IdrisModel()
model: IdrisModel = new IdrisModel(windowsToWsl)
messages: MessagePanelView = new MessagePanelView({
title: 'Idris Messages',
})
Expand Down
21 changes: 18 additions & 3 deletions lib/idris-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export class IdrisModel {
warnings: any = {}
compilerOptions: CompilerOptions = { pkgs: [] }
oldCompilerOptions: CompilerOptions = { pkgs: [] }
private _windowsToWsl: (path: string) => Promise<string>

constructor() {
constructor(windowsToWsl: (path: string) => Promise<string>) {
this.handleCommand = this.handleCommand.bind(this)
this._windowsToWsl = windowsToWsl
}

ideMode(compilerOptions: any) {
Expand Down Expand Up @@ -130,7 +132,10 @@ export class IdrisModel {
}

changeDirectory(dir: string) {
return this.interpret(`:cd ${dir}`)
const platformDir = this._toPlatformPath(dir)
return platformDir.flatMap((dir) => {
return this.interpret(`:cd ${dir}`)
})
}

load(uri: string) {
Expand All @@ -147,7 +152,9 @@ export class IdrisModel {
}
})()

return cd.flatMap((_) => {
const platformUri = this._toPlatformPath(uri)

return cd.zip(platformUri).flatMap(([_, uri]) => {
return this.prepareCommand({ type: 'load-file', fileName: uri })
})
}
Expand Down Expand Up @@ -219,4 +226,12 @@ export class IdrisModel {
browseNamespace(namespace: string) {
return this.prepareCommand({ type: 'browse-namespace', namespace })
}

private _toPlatformPath(path: string): Rx.Observable<string> {
return this._shouldUseWsl ? Rx.Observable.fromPromise(this._windowsToWsl(path)) : Rx.Observable.of(path)
}

private get _shouldUseWsl(): boolean {
return atom.config.get('language-idris.idrisInWsl')
}
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
"type": "boolean",
"default": false,
"description": "Enable ligatures in the various idris panels"
},
"idrisInWsl": {
"title": "Integrate with an Idris installation in WSL",
"type": "boolean",
"default": false,
"description": "Enable this if you installed Idris in WSL but run the editor in Windows"
}
},
"providedServices": {
Expand Down Expand Up @@ -84,7 +90,8 @@
"preact": "10.4.4",
"rx-lite": "4.0.8",
"tslib": "1.11.1",
"typescript": "3.9.2"
"typescript": "3.9.2",
"wsl-path": "^3.0.1"
},
"devDependencies": {
"@types/atom": "1.40.4",
Expand Down
61 changes: 61 additions & 0 deletions spec/idris-model-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ IdrisModel } = require "../lib/idris-model"
Rx = require "rx-lite"

describe "Idris model", ->
it "should use wsl-path to change directory when WSL integration is enabled", ->
finished = false
spyOn(atom.config, "get").andReturn true
idrisModel = new IdrisModel(-> Promise.resolve("/wsl/path"))
interpretSpy = spyOn(idrisModel, "interpret").andReturn Rx.Observable.of(null)
runs ->
idrisModel.changeDirectory("C:\\windows\\path").subscribe ->
finished = true
waitsFor (-> finished), "changeDirectory should complete", 500
runs ->
expect(interpretSpy).toHaveBeenCalledWith(":cd /wsl/path")

it "should not use wsl-path to change directory when WSL integration is disabled", ->
finished = false
spyOn(atom.config, "get").andReturn false
wslPathSpy = jasmine.createSpy("windowsToWsl")
idrisModel = new IdrisModel(wslPathSpy)
interpretSpy = spyOn(idrisModel, "interpret").andReturn Rx.Observable.of(null)
runs ->
idrisModel.changeDirectory("C:\\windows\\path").subscribe ->
finished = true
waitsFor (-> finished), "changeDirectory should complete", 500
runs ->
expect(interpretSpy).toHaveBeenCalledWith(":cd C:\\windows\\path")
expect(wslPathSpy).not.toHaveBeenCalled()

it "should use wsl-path to load file when WSL integration is enabled", ->
finished = false
spyOn(atom.config, "get").andReturn true
idrisModel = new IdrisModel(-> Promise.resolve("/wsl/path"))
prepareCommandSpy = spyOn(idrisModel, "prepareCommand").andReturn Rx.Observable.of(null)
runs ->
idrisModel.load("C:\\windows\\path").subscribe ->
finished = true
waitsFor (-> finished), "load should complete", 500
runs ->
expect(prepareCommandSpy).toHaveBeenCalledWith({
type: "load-file"
fileName: "/wsl/path"
})

it "should not use wsl-path to load file when WSL integration is disabled", ->
finished = false
spyOn(atom.config, "get").andReturn false
wslPathSpy = jasmine.createSpy("windowsToWsl")
idrisModel = new IdrisModel(wslPathSpy)
prepareCommandSpy = spyOn(idrisModel, "prepareCommand").andReturn Rx.Observable.of(null)
runs ->
idrisModel.load("C:\\windows\\path").subscribe ->
finished = true
waitsFor (-> finished), "load should complete", 500
runs ->
expect(prepareCommandSpy).toHaveBeenCalledWith({
type: "load-file"
fileName: "C:\\windows\\path"
})
expect(wslPathSpy).not.toHaveBeenCalled()