-
Notifications
You must be signed in to change notification settings - Fork 847
Added Colorization/Brace Matching Roslyn Services #993
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
Changes from all commits
7b47e32
534626a
5720e91
f588f87
3e31561
569db4c
5e75a0e
25e9737
b56550c
2b4b731
30c92a6
1da0ea6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| module internal Microsoft.FSharp.Compiler.Lexhelp | ||
|
|
||
| open System | ||
| open System.IO | ||
| open System.Text | ||
| open Internal.Utilities | ||
| open Internal.Utilities.Collections | ||
|
|
@@ -335,14 +337,18 @@ module Keywords = | |
| match s with | ||
| | "__SOURCE_DIRECTORY__" -> | ||
| let filename = fileOfFileIndex lexbuf.StartPos.FileIndex | ||
| let dirname = if filename = stdinMockFilename then | ||
| System.IO.Directory.GetCurrentDirectory() | ||
| else | ||
| filename |> FileSystem.GetFullPathShim (* asserts that path is already absolute *) | ||
| |> System.IO.Path.GetDirectoryName | ||
| let dirname = | ||
| if String.IsNullOrWhiteSpace(filename) then | ||
| String.Empty | ||
| else if filename = stdinMockFilename then | ||
| Directory.GetCurrentDirectory() | ||
| else | ||
| filename | ||
| |> FileSystem.GetFullPathShim (* asserts that path is already absolute *) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confused by the comment. The implementation of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a proxy for |
||
| |> Path.GetDirectoryName | ||
| KEYWORD_STRING dirname | ||
| | "__SOURCE_FILE__" -> | ||
| KEYWORD_STRING (System.IO.Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex))) | ||
| KEYWORD_STRING (Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex))) | ||
| | "__LINE__" -> | ||
| KEYWORD_STRING (string lexbuf.StartPos.Line) | ||
| | _ -> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,9 @@ open System.Collections.Generic | |
| open Microsoft.FSharp.Compiler | ||
| open Microsoft.FSharp.Compiler.Range | ||
|
|
||
| type Position = int * int | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do these two ints represent?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line and Column (lexer code in the compiler service).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we get comment precising if they differ from range in compiler itself: https://github.com/Microsoft/visualfsharp/blob/2ffb0b6c99a15b364af309dabb12504cc72ad3be/src/fsharp/range.fsi#L91 If they are supposed to conform to range.fsi, maybe reuse that type, if not it wouldn't hurt to state in a comment how the indices are considered in this area of the code. This is an area where technical debt was accumulated in VFPT (where + 1 and - 1 are applied in various places without greatest consistency), we intend to standardize on FSharp.Compiler.Services types and convert the one from VS pretty close in the UI before involving our services implementing the logic in relation to FCS.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smoothdeveloper This is exposing the type that was defined in ServiceLexing.fs. No new behavior was introduced. |
||
| type Range = Position * Position | ||
|
|
||
| /// Represents encoded information for the end-of-line continutation of lexing | ||
| type FSharpTokenizerLexState = int64 | ||
|
|
||
|
|
@@ -49,9 +52,7 @@ type internal FSharpTokenColorKind = | |
| | PreprocessorKeyword = 8 | ||
| | Number = 9 | ||
| | Operator = 10 | ||
| #if COLORIZE_TYPES | ||
| | TypeName = 11 | ||
| #endif | ||
|
|
||
| /// Gives an indication of what should happen when the token is typed in an IDE | ||
| type internal FSharpTokenTriggerClass = | ||
|
|
@@ -205,7 +206,7 @@ type internal FSharpLineTokenizer = | |
| /// Tokenizer for a source file. Holds some expensive-to-compute resources at the scope of the file. | ||
| [<Sealed>] | ||
| type internal FSharpSourceTokenizer = | ||
| new : conditionalDefines:string list * fileName:string -> FSharpSourceTokenizer | ||
| new : conditionalDefines:string list * fileName:Option<string> -> FSharpSourceTokenizer | ||
| member CreateLineTokenizer : lineText:string -> FSharpLineTokenizer | ||
| member CreateBufferTokenizer : bufferFiller:(char[] * int * int -> int) -> FSharpLineTokenizer | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1473,12 +1473,10 @@ type TypeCheckInfo | |
| // custom builders, custom operations get colored as keywords | ||
| | CNR(_, (Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use, _, _, _, m) -> | ||
| yield (m, FSharpTokenColorKind.Keyword) | ||
| #if COLORIZE_TYPES | ||
| // types get colored as types when they occur in syntactic types or custom attributes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned that the type colorization logic may be pretty buggy or at least untested. Please compare with the Visual F# Power Tools paths, which use the FCS Symbols API to do colorization rather than this code (which is old and not exercised by any clients at the moment - one of the reasons we added the Symbols API was to be able to do this outside FCS rather than inside)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dsyme ATM, we still need intellisense for type colorization to work. I've chosen to start this in a separate PR, because the current one is getting huge already. I'm going to rewrite/refactor the type colorization code in Colorize.fs (is this the one you meant?) and add many more tests to check for this specifically. |
||
| // typevariables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords | ||
| | CNR(_, (Item.TypeVar _ | Item.Types _ | Item.UnqualifiedType _) , (ItemOccurence.UseInType | ItemOccurence.UseInAttribute), _, _, _, m) -> | ||
| yield (m, FSharpTokenColorKind.TypeName) | ||
| #endif | ||
| | _ -> () | ||
| |] | ||
| member x.ScopeResolutions = sResolutions | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a way for F# to hook the file system in the unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In F# code,
__SOURCE_DIRECTORY__and__SOURCE_FILE__are substituted with string literals: https://msdn.microsoft.com/en-us/library/dd233234.aspxThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is guarding against cases where Roslyn APIs don't provide the document name (like colorizing a particular span).