Skip to content

Commit

Permalink
Fixes #112
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhmale committed May 21, 2017
1 parent ad295dd commit d041897
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/analysis/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require("fs")
const glob = require("glob")
const _ = require('lodash')
const vscode = require('vscode')
const Maybe = require('../maybe.js')

const idrisKeywords = [
"if",
Expand Down Expand Up @@ -206,8 +207,10 @@ let getAllFiles = (ext) => {
return file.endsWith(`.${ext}`)
})
} else {
let uri = vscode.window.activeTextEditor.document.uri.fsPath
return uri.endsWith(ext) ? [uri] : []
return Maybe.of(vscode.window.activeTextEditor)
.map((editor) => { return editor.document.uri.fsPath })
.map((uri) => { return uri.endsWith(ext) ? [uri] : [] })
.getOrElse([])
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const vscode = require('vscode')
const fs = require('fs')
const cp = require('child_process')
const path = require('path')
const Maybe = require('./maybe')

const IDRIS_MODE = [
{ language: 'idris', scheme: 'file' },
Expand Down Expand Up @@ -71,13 +72,15 @@ let reInitialize = () => {
}

let withCompilerOptions = (callback) => {
let document = vscode.window.activeTextEditor.document
if (!IDRIS_MODE.map((mode) => { return mode.language }).includes(document.languageId)) return
let uri = document.uri.fsPath

getCompilerOptsPromise().subscribe((compilerOptions) => {
commands.initialize(compilerOptions)
callback(uri)
Maybe.of(vscode.window.activeTextEditor).map((editor) => {
let document = editor.document
if (!IDRIS_MODE.map((mode) => { return mode.language }).includes(document.languageId)) return
let uri = document.uri.fsPath

getCompilerOptsPromise().subscribe((compilerOptions) => {
commands.initialize(compilerOptions)
callback(uri)
})
})
}

Expand Down
16 changes: 10 additions & 6 deletions src/idris/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const common = require('../analysis/common')
const findDefinition = require('../analysis/find-definition')
const Rx = require('rx-lite')
const path = require('path')
const Maybe = require('../maybe')

let model = null
let checkNotTotalModel = null
Expand Down Expand Up @@ -102,13 +103,16 @@ let getWord = () => {
* Get the column of the first character of a concrete line of code
*/
let getStartColumn = (line) => {
if (line >= vscode.window.activeTextEditor.document.lineCount)
return 0
return Maybe.of(vscode.window.activeTextEditor).map((editor) => {
let document = editor.document

let document = vscode.window.activeTextEditor.document
let textAtLine = document.lineAt(line).text
let column = textAtLine.indexOf(textAtLine.trim())
return column
if (line >= document.lineCount)
return 0

let textAtLine = document.lineAt(line).text
let column = textAtLine.indexOf(textAtLine.trim())
return column
}).getOrElse(0)
}

let clearTotalityDiagnostics = () => {
Expand Down
42 changes: 42 additions & 0 deletions src/maybe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//http://jrsinclair.com/articles/2016/marvellously-mysterious-javascript-maybe-monad/

var Maybe = module.exports = function (val) {
this.__value = val
}

Maybe.of = function (val) {
return new Maybe(val)
}

Maybe.prototype.isNothing = function () {
return (this.__value === null || this.__value === undefined)
}

Maybe.prototype.map = function (f) {
if (this.isNothing()) {
return Maybe.of(null)
}
return Maybe.of(f(this.__value))
}

Maybe.prototype.foreach = function (f) {
if (!this.isNothing()) {
f(this.__value)
}
}

Maybe.prototype.orElse = function (d) {
if (this.isNothing()) {
return Maybe.of(d)
}

return this
}

Maybe.prototype.getOrElse = function (d) {
if (this.isNothing()) {
return d
}

return this.__value
}
7 changes: 5 additions & 2 deletions src/providers/ipkg/completionProvider.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const common = require('../../analysis/common')
const completionUtil = require('../completionUtil')
const vscode = require('vscode')
const Maybe = require('../../maybe')

let identList

let buildCompletionList = () => {
let uri = vscode.window.activeTextEditor.document.uri.fsPath
identList = common.getIdents(uri)
Maybe.of(vscode.window.activeTextEditor).map((editor) => {
let uri = editor.document.uri.fsPath
identList = common.getIdents(uri)
})
}

let IPKGCompletionProvider = (function () {
Expand Down

0 comments on commit d041897

Please sign in to comment.