Skip to content

Commit 97aace1

Browse files
committed
Merge branch 'Krzysztof-Cieslak-CompletionGlyphs'
2 parents a62b496 + 41cdc3f commit 97aace1

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

FSharp.AutoComplete/Program.fs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ type Location =
4848
Column: int
4949
}
5050

51+
type CompletionResponse =
52+
{
53+
Name: string
54+
Glyph: string
55+
GlyphChar: string
56+
}
57+
5158
type ProjectResponse =
5259
{
5360
Project: string
@@ -267,6 +274,48 @@ module internal CommandInput =
267274
let cmds = compilerlocation <|> outputmode <|> helptext <|> help <|> declarations <|> parse <|> project <|> completionTipOrDecl <|> quit <|> error
268275
reader |> Parsing.getFirst cmds
269276

277+
module internal CompletionUtils =
278+
let map =
279+
[ 0x0000, ("Class", "C")
280+
0x0003, ("Enum", "E")
281+
0x00012, ("Struct", "S")
282+
0x00018, ("Struct", "S") (* value type *)
283+
0x0002, ("Delegate", "D")
284+
0x0008, ("Interface", "I")
285+
0x000e, ("Module", "N") (* module *)
286+
0x000f, ("Namespace", "N")
287+
0x000c, ("Method", "M")
288+
0x000d, ("Extension Method", "M") (* method2 ? *)
289+
0x00011, ("Property", "P")
290+
0x0005, ("Event", "e")
291+
0x0007, ("Field", "F") (* fieldblue ? *)
292+
0x0020, ("Field", "F") (* fieldyellow ? *)
293+
0x0001, ("Field", "F") (* const *)
294+
0x0004, ("Property", "P") (* enummember *)
295+
0x0006, ("Exception", "X") (* exception *)
296+
0x0009, ("Text File Icon", "t") (* TextLine *)
297+
0x000a, ("Regular File", "R") (* Script *)
298+
0x000b, ("Script", "s") (* Script2 *)
299+
0x0010, ("Tip of the day", "t") (* Formula *);
300+
0x00013, ("Class", "C") (* Template *)
301+
0x00014, ("Class", "C") (* Typedef *)
302+
0x00015, ("Type", "T") (* Type *)
303+
0x00016, ("Type", "T") (* Union *)
304+
0x00017, ("Field", "F") (* Variable *)
305+
0x00019, ("Class", "C") (* Intrinsic *)
306+
0x0001f, ("Other", "o") (* error *)
307+
0x00021, ("Other", "o") (* Misc1 *)
308+
0x0022, ("Other", "o") (* Misc2 *)
309+
0x00023, ("Other", "o") (* Misc3 *) ] |> Map.ofSeq
310+
311+
/// Translates icon code that we get from F# language service into a MonoDevelop icon
312+
let getIcon glyph =
313+
match map.TryFind (glyph / 6), map.TryFind (glyph % 6) with
314+
| Some(s), _ -> s // Is the second number good for anything?
315+
| _, _ -> ("", "")
316+
317+
318+
270319
// --------------------------------------------------------------------------------------
271320
// Main application command-line loop
272321
// --------------------------------------------------------------------------------------
@@ -488,7 +537,9 @@ module internal Main =
488537
prAsJson { Kind = "helptext"; Data = helptext }
489538

490539
prAsJson { Kind = "completion"
491-
Data = [ for d in decls.Items do yield d.Name ] }
540+
Data = [ for d in decls.Items do
541+
let (glyph, glyphChar) = CompletionUtils.getIcon d.Glyph
542+
yield { Name = d.Name; Glyph = glyph; GlyphChar = glyphChar } ] }
492543

493544
let helptext =
494545
Seq.fold (fun m (d: FSharpDeclarationListItem) -> Map.add d.Name d.DescriptionText m) Map.empty decls.Items

FSharp.AutoComplete/test/integration/ErrorTestsJson/output.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
{"Kind":"INFO","Data":"Synchronous parsing started"}
55
{"Kind":"errors","Data":[{"StartLine":7,"StartLineAlternate":8,"EndLine":7,"EndLineAlternate":8,"StartColumn":12,"EndColumn":19,"Severity":"Error","Message":"The value or constructor 'unnamed' is not defined","Subcategory":"typecheck","FileName":"<absolute path removed>/test/integration/ErrorTestsJson/Script.fsx"}]}
66
{"Kind":"helptext","Data":{"func":"val func : x:int -> int"}}
7-
{"Kind":"completion","Data":["func"]}
7+
{"Kind":"completion","Data":[{"Name":"func","Glyph":"Method","GlyphChar":"M"}]}
88
{"Kind":"helptext","Data":{"func":"val func : x:int -> int"}}
9-
{"Kind":"completion","Data":["func"]}
9+
{"Kind":"completion","Data":[{"Name":"func","Glyph":"Method","GlyphChar":"M"}]}

FSharp.AutoComplete/test/integration/Test1Json/output.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
{"Kind":"INFO","Data":"Synchronous parsing started"}
77
{"Kind":"errors","Data":[]}
88
{"Kind":"helptext","Data":{"funky":"val funky : x:int -> int"}}
9-
{"Kind":"completion","Data":["funky"]}
9+
{"Kind":"completion","Data":[{"Name":"funky","Glyph":"Method","GlyphChar":"M"}]}
1010
{"Kind":"helptext","Data":{"Equals":"System.Object.Equals(obj: obj) : bool"}}
11-
{"Kind":"completion","Data":["Equals","GetHashCode","GetType","Terrific","ToString"]}
11+
{"Kind":"completion","Data":[{"Name":"Equals","Glyph":"Method","GlyphChar":"M"},{"Name":"GetHashCode","Glyph":"Method","GlyphChar":"M"},{"Name":"GetType","Glyph":"Method","GlyphChar":"M"},{"Name":"Terrific","Glyph":"Method","GlyphChar":"M"},{"Name":"ToString","Glyph":"Method","GlyphChar":"M"}]}
1212
{"Kind":"helptext","Data":{"Bar":"union case FileTwo.Foo.Bar: FileTwo.Foo"}}
13-
{"Kind":"completion","Data":["Bar","Foo","NewObjectType","Qux","add","addition"]}
13+
{"Kind":"completion","Data":[{"Name":"Bar","Glyph":"Property","GlyphChar":"P"},{"Name":"Foo","Glyph":"Type","GlyphChar":"T"},{"Name":"NewObjectType","Glyph":"Class","GlyphChar":"C"},{"Name":"Qux","Glyph":"Property","GlyphChar":"P"},{"Name":"add","Glyph":"Method","GlyphChar":"M"},{"Name":"addition","Glyph":"Method","GlyphChar":"M"}]}
1414
{"Kind":"helptext","Data":{"func":"val func : x:int -> int"}}
15-
{"Kind":"completion","Data":["func"]}
15+
{"Kind":"completion","Data":[{"Name":"func","Glyph":"Method","GlyphChar":"M"}]}
1616
{"Kind":"helptext","Data":{"Bar":"union case FileTwo.Foo.Bar: FileTwo.Foo"}}
17-
{"Kind":"completion","Data":["Bar","Foo","NewObjectType","Qux","add","addition"]}
17+
{"Kind":"completion","Data":[{"Name":"Bar","Glyph":"Property","GlyphChar":"P"},{"Name":"Foo","Glyph":"Type","GlyphChar":"T"},{"Name":"NewObjectType","Glyph":"Class","GlyphChar":"C"},{"Name":"Qux","Glyph":"Property","GlyphChar":"P"},{"Name":"add","Glyph":"Method","GlyphChar":"M"},{"Name":"addition","Glyph":"Method","GlyphChar":"M"}]}
1818
{"Kind":"tooltip","Data":"val add : x:int -> y:int -> int\n\nFull name: FileTwo.add"}
1919
{"Kind":"tooltip","Data":"val func : x:int -> int\n\nFull name: Program.X.func"}
2020
{"Kind":"tooltip","Data":"val testval : FileTwo.NewObjectType\n\nFull name: Program.testval"}

0 commit comments

Comments
 (0)