Skip to content

Commit 7744f53

Browse files
author
Omar Tawfik
committed
Merge pull request #993 from otawfik-ms/correcthistory
Added Colorization/Brace Matching Roslyn Services
2 parents f3f6175 + 1da0ea6 commit 7744f53

20 files changed

+1523
-1307
lines changed

src/fsharp/lexhelp.fs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module internal Microsoft.FSharp.Compiler.Lexhelp
44

5+
open System
6+
open System.IO
57
open System.Text
68
open Internal.Utilities
79
open Internal.Utilities.Collections
@@ -335,14 +337,18 @@ module Keywords =
335337
match s with
336338
| "__SOURCE_DIRECTORY__" ->
337339
let filename = fileOfFileIndex lexbuf.StartPos.FileIndex
338-
let dirname = if filename = stdinMockFilename then
339-
System.IO.Directory.GetCurrentDirectory()
340-
else
341-
filename |> FileSystem.GetFullPathShim (* asserts that path is already absolute *)
342-
|> System.IO.Path.GetDirectoryName
340+
let dirname =
341+
if String.IsNullOrWhiteSpace(filename) then
342+
String.Empty
343+
else if filename = stdinMockFilename then
344+
Directory.GetCurrentDirectory()
345+
else
346+
filename
347+
|> FileSystem.GetFullPathShim (* asserts that path is already absolute *)
348+
|> Path.GetDirectoryName
343349
KEYWORD_STRING dirname
344350
| "__SOURCE_FILE__" ->
345-
KEYWORD_STRING (System.IO.Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex)))
351+
KEYWORD_STRING (Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex)))
346352
| "__LINE__" ->
347353
KEYWORD_STRING (string lexbuf.StartPos.Line)
348354
| _ ->

src/fsharp/vs/ServiceLexing.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ type FSharpTokenColorKind =
8888
| PreprocessorKeyword = 8
8989
| Number = 9
9090
| Operator = 10
91-
#if COLORIZE_TYPES
9291
| TypeName = 11
93-
#endif
9492

9593
/// Categorize an action the editor should take in response to a token, e.g. brace matching
9694
///
@@ -477,15 +475,17 @@ type SingleLineTokenState =
477475
[<Sealed>]
478476
type FSharpLineTokenizer(lexbuf: UnicodeLexing.Lexbuf,
479477
maxLength: int option,
480-
filename : string,
478+
filename : Option<string>,
481479
lexArgsLightOn : lexargs,
482480
lexArgsLightOff : lexargs
483481
) =
484482

485483
let skip = false // don't skip whitespace in the lexer
486484

487485
let mutable singleLineTokenState = SingleLineTokenState.BeforeHash
488-
let fsx = CompileOps.IsScript(filename)
486+
let fsx = match filename with
487+
| None -> false
488+
| Some(value) -> CompileOps.IsScript(value)
489489

490490
// ----------------------------------------------------------------------------------
491491
// This implements post-processing of #directive tokens - not very elegant, but it works...
@@ -552,7 +552,9 @@ type FSharpLineTokenizer(lexbuf: UnicodeLexing.Lexbuf,
552552

553553

554554

555-
do resetLexbufPos filename lexbuf
555+
do match filename with
556+
| None -> lexbuf.EndPos <- Internal.Utilities.Text.Lexing.Position.Empty
557+
| Some(value) -> resetLexbufPos value lexbuf
556558

557559
member x.ScanToken(lexintInitial) : Option<FSharpTokenInfo> * FSharpTokenizerLexState =
558560
use unwindBP = PushThreadBuildPhaseUntilUnwind (BuildPhase.Parse)
@@ -736,7 +738,7 @@ type FSharpLineTokenizer(lexbuf: UnicodeLexing.Lexbuf,
736738
LexerStateEncoding.encodeLexCont colorState ncomments position ifdefStack light
737739

738740
[<Sealed>]
739-
type FSharpSourceTokenizer(defineConstants : string list, filename : string) =
741+
type FSharpSourceTokenizer(defineConstants : string list, filename : Option<string>) =
740742
let lexResourceManager = new Lexhelp.LexResourceManager()
741743

742744
let lexArgsLightOn = mkLexargs(filename,defineConstants,LightSyntaxStatus(true,false),lexResourceManager, ref [],DiscardErrorsLogger)

src/fsharp/vs/ServiceLexing.fsi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ open System.Collections.Generic
1515
open Microsoft.FSharp.Compiler
1616
open Microsoft.FSharp.Compiler.Range
1717

18+
type Position = int * int
19+
type Range = Position * Position
20+
1821
/// Represents encoded information for the end-of-line continutation of lexing
1922
type FSharpTokenizerLexState = int64
2023

@@ -49,9 +52,7 @@ type internal FSharpTokenColorKind =
4952
| PreprocessorKeyword = 8
5053
| Number = 9
5154
| Operator = 10
52-
#if COLORIZE_TYPES
5355
| TypeName = 11
54-
#endif
5556

5657
/// Gives an indication of what should happen when the token is typed in an IDE
5758
type internal FSharpTokenTriggerClass =
@@ -205,7 +206,7 @@ type internal FSharpLineTokenizer =
205206
/// Tokenizer for a source file. Holds some expensive-to-compute resources at the scope of the file.
206207
[<Sealed>]
207208
type internal FSharpSourceTokenizer =
208-
new : conditionalDefines:string list * fileName:string -> FSharpSourceTokenizer
209+
new : conditionalDefines:string list * fileName:Option<string> -> FSharpSourceTokenizer
209210
member CreateLineTokenizer : lineText:string -> FSharpLineTokenizer
210211
member CreateBufferTokenizer : bufferFiller:(char[] * int * int -> int) -> FSharpLineTokenizer
211212

src/fsharp/vs/service.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,12 +1473,10 @@ type TypeCheckInfo
14731473
// custom builders, custom operations get colored as keywords
14741474
| CNR(_, (Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use, _, _, _, m) ->
14751475
yield (m, FSharpTokenColorKind.Keyword)
1476-
#if COLORIZE_TYPES
14771476
// types get colored as types when they occur in syntactic types or custom attributes
14781477
// typevariables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords
14791478
| CNR(_, (Item.TypeVar _ | Item.Types _ | Item.UnqualifiedType _) , (ItemOccurence.UseInType | ItemOccurence.UseInAttribute), _, _, _, m) ->
14801479
yield (m, FSharpTokenColorKind.TypeName)
1481-
#endif
14821480
| _ -> ()
14831481
|]
14841482
member x.ScopeResolutions = sResolutions

src/fsharp/vs/service.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ type internal FSharpChecker =
519519
/// This function is called when the configuration is known to have changed for reasons not encoded in the ProjectOptions.
520520
/// For example, dependent references may have been deleted or created.
521521
member InvalidateConfiguration: options: FSharpProjectOptions -> unit
522+
523+
/// Begin background parsing the given project.
524+
member StartBackgroundCompile: options: FSharpProjectOptions -> unit
522525

523526
/// Set the project to be checked in the background. Overrides any previous call to <c>CheckProjectInBackground</c>
524527
member CheckProjectInBackground: options: FSharpProjectOptions -> unit

vsintegration/src/FSharp.Editor/BraceCompletion.fs

Lines changed: 0 additions & 135 deletions
This file was deleted.

vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
<OtherFlags>$(OtherFlags) --warnon:1182 --subsystemversion:6.00</OtherFlags>
2323
</PropertyGroup>
2424
<ItemGroup>
25-
<Compile Include="TokenContext.fs" />
25+
<Compile Include="InternalsVisibleTo.fs" />
2626
<Compile Include="SmartIndent.fs" />
27+
<Compile Include="FSharpProjectSiteService.fs" />
28+
<Compile Include="FSharpContentType.fs" />
29+
<Compile Include="FSharpColorizationService.fs" />
30+
<Compile Include="FSharpBraceMatchingService.fs" />
2731
<Content Include="extension.vsixmanifest">
2832
<CopyToOutputDirectory>false</CopyToOutputDirectory>
2933
</Content>
30-
<Compile Include="BraceCompletion.fs" />
31-
<Compile Include="FSharpProjectSiteService.fs" />
32-
<Compile Include="FSharpContentType.fs" />
3334
</ItemGroup>
3435
<ItemGroup>
3536
<ProjectReference Include="..\..\..\src\fsharp\FSharp.Core\FSharp.Core.fsproj">
@@ -64,10 +65,13 @@
6465
<Reference Include="Microsoft.VisualStudio.Text.Logic" />
6566
<Reference Include="Microsoft.VisualStudio.CoreUtility" />
6667
<Reference Include="Microsoft.VisualStudio.OLE.Interop" />
67-
<Reference Include="Microsoft.VisualStudio.Shell" />
68+
<Reference Include="Microsoft.VisualStudio.Shell.$(VisualStudioVersion)" />
6869
<Reference Include="Microsoft.VisualStudio.Shell.Interop" />
6970
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" />
7071
<Reference Include="Microsoft.VisualStudio.TextManager.Interop" />
72+
<Reference Include="Microsoft.VisualStudio.Threading" />
73+
<Reference Include="PresentationCore" />
74+
<Reference Include="WindowsBase" />
7175
<Reference Include="System.Composition.AttributedModel">
7276
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.Composition.$(MicrosoftCompositionVersion)\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
7377
</Reference>

0 commit comments

Comments
 (0)