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

"LineLens" #510

Merged
merged 1 commit into from
Sep 4, 2017
Merged
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
8 changes: 4 additions & 4 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GITHUB
modules/Octokit/Octokit.fsx (291f58cc70aba6dd871cf18e66d2d88357e4f208)
Octokit (>= 0.20)
remote: Ionide/ionide-vscode-helpers
Fable.Import.Axios.fs (42949401319091b80cd8038524335a54491e4fe1)
Fable.Import.VSCode.fs (42949401319091b80cd8038524335a54491e4fe1)
Fable.Import.ws.fs (42949401319091b80cd8038524335a54491e4fe1)
Helpers.fs (42949401319091b80cd8038524335a54491e4fe1)
Fable.Import.Axios.fs (84f4fb08ebc2b8eab40c851cb046e440c0646c2b)
Fable.Import.VSCode.fs (84f4fb08ebc2b8eab40c851cb046e440c0646c2b)
Fable.Import.ws.fs (84f4fb08ebc2b8eab40c851cb046e440c0646c2b)
Helpers.fs (84f4fb08ebc2b8eab40c851cb046e440c0646c2b)
65 changes: 44 additions & 21 deletions release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
"group": "1_run@1"
}
],
"editor/context":[
"editor/context": [
{
"command": "fsharp.generateDoc",
"group": "1_modification",
Expand Down Expand Up @@ -695,13 +695,13 @@
"description": "Automatically shows Expecto output panel"
},
"FSharp.msbuildLocation": {
"type":"string",
"default":"",
"type": "string",
"default": "",
"description": "Use a specific version of msbuild to build this project."
},
"FSharp.msbuildAutoshow": {
"type":"boolean",
"default":true,
"type": "boolean",
"default": true,
"description": "Automatically shows Expecto output panel"
},
"FSharp.msbuildHost": {
Expand All @@ -716,7 +716,7 @@
]
},
"FSharp.resolveNamespaces": {
"type":"boolean",
"type": "boolean",
"default": false,
"description": "Enables `resolve unopened namespaces and modules` code fix. Not stable, can crash FSAC - use at your own risk."
},
Expand All @@ -726,9 +726,32 @@
"description": "Enables solution explorer - experimental feature."
},
"FSharp.excludeProjectDirectories": {
"type":"array",
"default": [".git", "paket-files"],
"type": "array",
"default": [
".git",
"paket-files"
],
"description": "Directories in the array are excluded from project file search. Requires restart"
},
"FSharp.lineLens.enabled": {
"type": "string",
"description": "Usage mode for LineLens",
"enum": [
"never",
"replaceCodeLens",
"always"
],
"default": "never"
},
"FSharp.lineLens.prefix": {
"type": "string",
"description": "The prefix displayed before the signature",
"default": " // "
},
"FSharp.lineLens.color": {
"type": "string",
"description": "Color of the line lens, any css syntax or 'theme(...)' for a theme color.",
"default": "theme(editorCodeLens.foreground)"
}
}
},
Expand All @@ -750,22 +773,22 @@
"fileLocation": "absolute",
"background": {
"activeOnStart": true,
"beginsPattern":{
"regexp": "webpack: Compiling"
"beginsPattern": {
"regexp": "webpack: Compiling"
},
"endsPattern":{
"regexp": "webpack: (Compiled successfully|Failed to compile)"
"endsPattern": {
"regexp": "webpack: (Compiled successfully|Failed to compile)"
}
},
"pattern": {
"regexp": "(.*)\\((\\d+),(\\d+),(\\d+),(\\d+)\\)\\s*:\\s*(warning|error) FABLE\\s*:\\s*(.*)$",
"file": 1,
"line": 2,
"column": 3,
"endLine": 4,
"endColumn": 5,
"severity": 6,
"message": 7
"regexp": "(.*)\\((\\d+),(\\d+),(\\d+),(\\d+)\\)\\s*:\\s*(warning|error) FABLE\\s*:\\s*(.*)$",
"file": 1,
"line": 2,
"column": 3,
"endLine": 4,
"endColumn": 5,
"severity": 6,
"message": 7
}
}
]
Expand All @@ -785,7 +808,7 @@
"vscode.fsharp"
],
"scripts": {
"prebuild":"npm update",
"prebuild": "npm update",
"build": "fable ../src/Ionide.FSharp.fsproj -o ../release -m commonjs --verbose"
},
"dependencies": {
Expand Down
86 changes: 50 additions & 36 deletions src/Components/CodeLens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,58 @@ module CodeLens =
let newHeight = change.text.ToCharArray() |> Seq.sumBy (fun n -> if n = '\n' then 1 else 0)
newHeight - oldHeight

let formatSignature (sign : string) : string =
let sign =
match sign with
| StartsWith "val" _
| StartsWith "member" _
| StartsWith "abstract" _
| StartsWith "static" _
| StartsWith "override" _ -> sign
| _ ->
match sign.IndexOf "(" with
| i when i > 0 ->
sign.Substring(0, i) + ":" + sign.Substring(i+1)
| _ -> sign

let sign = if sign.Contains ":" then sign.Split(':').[1 ..] |> String.concat ":" else sign
let parms = sign.Split([|"->"|], StringSplitOptions.RemoveEmptyEntries)
parms
|> Seq.map (function
| Contains "(requires" p -> p
| Contains "*" p ->
p.Split '*' |> Seq.map (fun z -> if z.Contains ":" then z.Split(':').[1] else z) |> String.concat "* "
| Contains ":" p ->
p.Split(':').[1]
| p -> p)
|> Seq.map String.trim
|> String.concat " -> "

let interestingSymbolPositions (symbols: Symbols[]): DTO.Range[] =
symbols |> Array.collect(fun syms ->
let interestingNested = syms.Nested |> Array.choose (fun sym ->
if sym.GlyphChar <> "Fc"
&& sym.GlyphChar <> "M"
&& sym.GlyphChar <> "F"
&& sym.GlyphChar <> "P"
|| sym.IsAbstract
|| sym.EnclosingEntity = "I" // interface
|| sym.EnclosingEntity = "R" // record
|| sym.EnclosingEntity = "D" // DU
|| sym.EnclosingEntity = "En" // enum
|| sym.EnclosingEntity = "E" // exception
then None
else Some sym.BodyRange)

if syms.Declaration.GlyphChar <> "Fc" then
interestingNested
else
interestingNested |> Array.append [|syms.Declaration.BodyRange|])

let private createProvider () =
let symbolsToCodeLens (doc : TextDocument) (symbols: Symbols[]) : CodeLens[] =
symbols |> Array.collect (fun syms ->
let range = CodeRange.fromDTO syms.Declaration.BodyRange
let codeLens = CodeLens range

let codeLenses = syms.Nested |> Array.choose (fun sym ->
if sym.GlyphChar <> "Fc"
&& sym.GlyphChar <> "M"
&& sym.GlyphChar <> "F"
&& sym.GlyphChar <> "P"
|| sym.IsAbstract
|| sym.EnclosingEntity = "I" // interface
|| sym.EnclosingEntity = "R" // record
|| sym.EnclosingEntity = "D" // DU
|| sym.EnclosingEntity = "En" // enum
|| sym.EnclosingEntity = "E" // exception
then None
else Some (CodeLens (CodeRange.fromDTO sym.BodyRange)))

if syms.Declaration.GlyphChar <> "Fc" then codeLenses
else
codeLenses |> Array.append [|codeLens|])

let formatSignature (sign : SignatureData) : string =
let args =
sign.Parameters
|> List.map (fun group ->
group |> List.map (fun p ->
p.Type
)
|> String.concat " * "
)
|> String.concat " -> "

if String.IsNullOrEmpty args then sign.OutputType else args + " -> " + sign.OutputType
interestingSymbolPositions symbols
|> Array.map (CodeRange.fromDTO >> CodeLens)

{ new CodeLensProvider with
member __.provideCodeLenses(doc, _) =
Expand Down Expand Up @@ -136,8 +152,6 @@ module CodeLens =
refresh.fire(-1)
()



let private fileOpenedHandler (event : TextEditor) =
if isNotNull event then
match event.document with
Expand Down
45 changes: 31 additions & 14 deletions src/Components/Errors.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ open System.Text.RegularExpressions


module Errors =
let private logger = ConsoleAndOutputChannelLogger(Some "Errors", Level.DEBUG, None, Some Level.DEBUG)

let mutable private currentDiagnostic = languages.createDiagnosticCollection ()

let private mapResult (ev : ParseResult) =

let errors =
ev.Data.Errors
|> Seq.distinctBy (fun error -> error.Severity, error.StartLine, error.StartColumn)
|> Seq.choose (fun error ->
try
if window.activeTextEditor.document.fileName |> String.startWith "\\" then None else
if error.FileName |> String.startWith "\\" then None else
let range = CodeRange.fromError error
let loc = Location (Uri.file error.FileName, range |> Case1)
let severity = if error.Severity = "Error" then 0 else 1
Expand All @@ -32,15 +33,30 @@ module Errors =
|> ResizeArray
ev.Data.File, errors

let private parse path text version =
LanguageService.parse path text version
|> Promise.map (fun (ev : ParseResult) ->
if isNotNull ev then
type DocumentParsedEvent = {
fileName: string
text: string
version: float
/// BEWARE: Live object, might have changed since the parsing
document: TextDocument
result: ParseResult
}

let private onDocumentParsedEmitter = EventEmitter<DocumentParsedEvent>()
let onDocumentParsed = onDocumentParsedEmitter.event;

let private parse (document : TextDocument) =
let fileName = document.fileName
let text = document.getText()
let version = document.version
LanguageService.parse document.fileName (document.getText()) document.version
|> Promise.map (fun (result : ParseResult) ->
if isNotNull result then
onDocumentParsedEmitter.fire { fileName = fileName; text = text; version = version; document = document; result = result }
// printf "CodeLens - File parsed"
CodeLens.refresh.fire (unbox version)
Linter.refresh.fire path
(Uri.file path, (mapResult ev |> snd |> Seq.map fst |> ResizeArray)) |> currentDiagnostic.set )

Linter.refresh.fire fileName
(Uri.file fileName, (mapResult result |> snd |> Seq.map fst |> ResizeArray)) |> currentDiagnostic.set )

let private parseFile (file : TextDocument) =
match file with
Expand All @@ -50,19 +66,20 @@ module Errors =
match prom with
| Some p -> p
|> Project.load
|> Promise.bind (fun _ -> parse path (file.getText ()) file.version)
| None -> parse path (file.getText ()) file.version
|> Promise.bind (fun _ -> parse file)
| None -> parse file
| _ -> Promise.lift (null |> unbox)

let mutable private timer = None

let private handler (event : TextDocumentChangeEvent) =
timer |> Option.iter(clearTimeout)
timer <- Some (setTimeout((fun _ ->
timer <- Some (setTimeout (fun _ ->
match event.document with
| Document.FSharp ->
parse (event.document.fileName) (event.document.getText ()) event.document.version
| _ -> promise { () } ), 1000.))
parse event.document
|> ignore
| _ -> () ) 1000.)

let private handlerSave (doc : TextDocument) =
match doc with
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module Expecto =
| _ -> (VSCode.getPluginPath "Ionide.Ionide-fsharp") + "/images/" + file |> Uri.file
opt.gutterIconPath <- unbox path
opt.overviewRulerLane <- Some OverviewRulerLane.Full
opt.overviewRulerColor <- Some "rgba(224, 64, 6, 0.7)"
opt.overviewRulerColor <- Some (Case1 "rgba(224, 64, 6, 0.7)")
window.createTextEditorDecorationType opt

let passedDecorationType =
Expand All @@ -167,7 +167,7 @@ module Expecto =
| _ -> (VSCode.getPluginPath "Ionide.Ionide-fsharp") + "/images/" + file |> Uri.file
opt.gutterIconPath <- unbox path
opt.overviewRulerLane <- Some OverviewRulerLane.Full
opt.overviewRulerColor <- Some "rgba(166, 215, 133, 0.7)"
opt.overviewRulerColor <- Some (Case1 "rgba(166, 215, 133, 0.7)")
window.createTextEditorDecorationType opt

let ignoredDecorationType =
Expand All @@ -180,7 +180,7 @@ module Expecto =
| _ -> (VSCode.getPluginPath "Ionide.Ionide-fsharp") + "/images/" + file |> Uri.file
opt.gutterIconPath <- unbox path
opt.overviewRulerLane <- Some OverviewRulerLane.Full
opt.overviewRulerColor <- Some "rgba(255, 188, 64, 0.7)"
opt.overviewRulerColor <- Some (Case1 "rgba(255, 188, 64, 0.7)")
window.createTextEditorDecorationType opt


Expand Down
Loading