diff --git a/src/fsharp/service/service.fs b/src/fsharp/service/service.fs index 0546dc9da90..5fffd8978d7 100644 --- a/src/fsharp/service/service.fs +++ b/src/fsharp/service/service.fs @@ -1545,11 +1545,6 @@ module internal Parser = let tokenizer = LexFilter.LexFilter(lightSyntaxStatus, options.CompilingFsLib, Lexer.token lexargs true, lexbuf) tokenizer.Lexer - // Adding this new-line character at the end of the source seems odd but is required for some unit tests - // Todo: fix tests - let addNewLine (source: string) = - if source.Length = 0 || not (source.[source.Length - 1] = '\n') then source + "\n" else source - let matchBraces(source, fileName, options: FSharpParsingOptions, userOpName: string) = let delayedLogger = CapturingErrorLogger("matchBraces") use _unwindEL = PushErrorLoggerPhaseUntilUnwind (fun _ -> delayedLogger) @@ -1563,7 +1558,7 @@ module internal Parser = use _unwindBP = PushThreadBuildPhaseUntilUnwind BuildPhase.Parse let matchingBraces = new ResizeArray<_>() - Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(addNewLine source), fileName) (fun lexbuf -> + Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(source), fileName) (fun lexbuf -> let errHandler = ErrorHandler(false, fileName, options.ErrorSeverityOptions, source) let lexfun = createLexerFunction fileName options lexbuf errHandler let parenTokensBalance t1 t2 = @@ -1599,7 +1594,7 @@ module internal Parser = use unwindBP = PushThreadBuildPhaseUntilUnwind BuildPhase.Parse let parseResult = - Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(addNewLine source), fileName) (fun lexbuf -> + Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(source), fileName) (fun lexbuf -> let lexfun = createLexerFunction fileName options lexbuf errHandler let isLastCompiland = fileName.Equals(options.LastFileName, StringComparison.CurrentCultureIgnoreCase) || diff --git a/tests/service/InteractiveCheckerTests.fs b/tests/service/InteractiveCheckerTests.fs index fba9adcb639..991a4c8d476 100644 --- a/tests/service/InteractiveCheckerTests.fs +++ b/tests/service/InteractiveCheckerTests.fs @@ -71,7 +71,7 @@ let input = let ``Test ranges - namespace`` () = let res = parseAndExtractRanges input printfn "Test ranges - namespace, res = %A" res - res |> shouldEqual [("N", ((4, 4), (6, 0))); ("Sample", ((4, 9), (4, 15)))] + res |> shouldEqual [("N", ((4, 4), (5, 4))); ("Sample", ((4, 9), (4, 15)))] let input2 = """ @@ -97,4 +97,4 @@ let input3 = let ``Test ranges - global namespace`` () = let res = parseAndExtractRanges input3 printfn "Test ranges - global namespace, res = %A" res - res |> shouldEqual [("", ((4, 4), (6, 0))); ("Sample", ((4, 9), (4, 15)))] + res |> shouldEqual [("", ((4, 4), (5, 4))); ("Sample", ((4, 9), (4, 15)))] diff --git a/tests/service/StructureTests.fs b/tests/service/StructureTests.fs index d87c3c18e78..16bee2c1c05 100644 --- a/tests/service/StructureTests.fs +++ b/tests/service/StructureTests.fs @@ -60,7 +60,7 @@ let (=>) (source: string) (expectedRanges: (Range * Range) list) = reraise() [] -let ``empty file``() = "" => [ (1, 0, 2, 0), (1, 0, 2, 0) ] +let ``empty file``() = "" => [] [] let ``nested module``() = diff --git a/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.Completion.fs b/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.Completion.fs index a16adb7450f..0ce3ef4ed8a 100644 --- a/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.Completion.fs +++ b/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.Completion.fs @@ -1531,8 +1531,11 @@ let x = new MyClass2(0) [] member public this.``AfterConstructor.5039_1``() = AssertAutoCompleteContainsNoCoffeeBreak - [ "let someCall(x) = null" - "let xe = someCall(System.IO.StringReader()." ] + [ +""" +let someCall(x) = null +let xe = someCall(System.IO.StringReader(). +""" ] "StringReader()." [ "ReadBlock" ] // should contain (StringReader) [ "LastIndexOfAny" ] // should not contain (String) @@ -1540,8 +1543,12 @@ let x = new MyClass2(0) [] member public this.``AfterConstructor.5039_1.CoffeeBreak``() = AssertAutoCompleteContains - [ "let someCall(x) = null" - "let xe = someCall(System.IO.StringReader()." ] + [ +""" +let someCall(x) = null +let xe = someCall(System.IO.StringReader(). +""" + ] "StringReader()." [ "ReadBlock" ] // should contain (StringReader) [ "LastIndexOfAny" ] // should not contain (String) @@ -4913,8 +4920,12 @@ let x = query { for bbbb in abbbbc(*D0*) do [] member this.``BadCompletionAfterQuicklyTyping.Bug130733.NowWorks``() = - let code = [ "let someCall(x) = null" - "let xe = someCall(System.IO.StringReader() "] + let code = [ +""" +let someCall(x) = null +let xe = someCall(System.IO.StringReader(). +""" + ] let (_, _, file) = this.CreateSingleFileProject(code) TakeCoffeeBreak(this.VS) diff --git a/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.ParameterInfo.fs b/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.ParameterInfo.fs index 8fe4486f160..711cd611e88 100644 --- a/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.ParameterInfo.fs +++ b/vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.ParameterInfo.fs @@ -195,12 +195,13 @@ type UsingMSBuild() = [] member public this.``Regression.StaticVsInstance.Bug3626.Case2``() = - let fileContent = """ - type Foo() = - member this.Bar(instanceReturnsString:int) = "hllo" - static member Bar(staticReturnsInt:int) = 13 - let Hoo = new Foo() - let y = Hoo.Bar((*Mark*)""" + let fileContent =""" +type Foo() = + member this.Bar(instanceReturnsString:int) = "hllo" + static member Bar(staticReturnsInt:int) = 13 +let Hoo = new Foo() +let y = Hoo.Bar((*Mark*) +""" this.VerifyParameterInfoAtStartOfMarker(fileContent,"(*Mark*)",[["instanceReturnsString"]]) [] @@ -256,7 +257,8 @@ type UsingMSBuild() = member public this.``Single.DotNet.StaticMethod``() = let code = ["#light" - "System.Object.ReferenceEquals(" + """System.Object.ReferenceEquals( + """ ] let (_, _, file) = this.CreateSingleFileProject(code) let gpatcc = GlobalParseAndTypeCheckCounter.StartNew(this.VS) @@ -600,7 +602,9 @@ type UsingMSBuild() = // Test PI does not pop up after non-parameterized properties and after values [] member public this.``Single.Locations.EndOfFile`` () = - this.TestSystematicParameterInfo("System.Console.ReadLine(", [ [] ]) + this.TestSystematicParameterInfo(""" +System.Console.ReadLine( +""", [ [] ]) // Test PI pop up on parameter list for attributes [] @@ -639,37 +643,57 @@ type UsingMSBuild() = [] member public this.``Single.Generics.MathAbs``() = let sevenTimes l = [ l; l; l; l; l; l; l ] - this.TestGenericParameterInfo("Math.Abs(", sevenTimes ["value"]) + this.TestGenericParameterInfo(""" +Math.Abs( +""", sevenTimes ["value"]) [] member public this.``Single.Generics.ExchangeInt``() = let sevenTimes l = [ l; l; l; l; l; l; l ] - this.TestGenericParameterInfo("Interlocked.Exchange(", sevenTimes ["location1"; "value"]) + this.TestGenericParameterInfo(""" +Interlocked.Exchange( +""", sevenTimes ["location1"; "value"]) [] member public this.``Single.Generics.Exchange``() = let sevenTimes l = [ l; l; l; l; l; l; l ] - this.TestGenericParameterInfo("Interlocked.Exchange(", sevenTimes ["location1"; "value"]) + this.TestGenericParameterInfo(""" +Interlocked.Exchange( +""", sevenTimes ["location1"; "value"]) [] member public this.``Single.Generics.ExchangeUnder``() = let sevenTimes l = [ l; l; l; l; l; l; l ] - this.TestGenericParameterInfo("Interlocked.Exchange<_> (", sevenTimes ["location1"; "value"]) + this.TestGenericParameterInfo(""" +Interlocked.Exchange<_> ( +""", sevenTimes ["location1"; "value"]) [] member public this.``Single.Generics.Dictionary``() = - this.TestGenericParameterInfo("System.Collections.Generic.Dictionary<_, option>(", [ []; ["capacity"]; ["comparer"]; ["capacity"; "comparer"]; ["dictionary"]; ["dictionary"; "comparer"] ]) + this.TestGenericParameterInfo(""" +System.Collections.Generic.Dictionary<_, option>( +""", [ []; ["capacity"]; ["comparer"]; ["capacity"; "comparer"]; ["dictionary"]; ["dictionary"; "comparer"] ]) [] member public this.``Single.Generics.List``() = - this.TestGenericParameterInfo("new System.Collections.Generic.List< _ > ( ", [ []; ["capacity"]; ["collection"] ]) + this.TestGenericParameterInfo(""" +new System.Collections.Generic.List< _ > ( +""", [ []; ["capacity"]; ["collection"] ]) [] member public this.``Single.Generics.ListInt``() = - this.TestGenericParameterInfo("System.Collections.Generic.List(", [ []; ["capacity"]; ["collection"] ]) + this.TestGenericParameterInfo(""" +System.Collections.Generic.List( +""", [ []; ["capacity"]; ["collection"] ]) [] member public this.``Single.Generics.EventHandler``() = - this.TestGenericParameterInfo("new System.EventHandler( ", [ [""] ]) // function arg doesn't have a name + this.TestGenericParameterInfo(""" +new System.EventHandler( +""", [ [""] ]) // function arg doesn't have a name [] member public this.``Single.Generics.EventHandlerEventArgs``() = - this.TestGenericParameterInfo("System.EventHandler(", [ [""] ]) // function arg doesn't have a name + this.TestGenericParameterInfo(""" +System.EventHandler( +""", [ [""] ]) // function arg doesn't have a name [] member public this.``Single.Generics.EventHandlerEventArgsNew``() = - this.TestGenericParameterInfo("new System.EventHandler ( ", [ [""] ]) // function arg doesn't have a name + this.TestGenericParameterInfo(""" +new System.EventHandler ( +""", [ [""] ]) // function arg doesn't have a name // Split into multiple lines using "\n" and find the index of "$" (and remove it from the text) member private this.ExtractLineInfo (line:string) = @@ -716,7 +740,9 @@ type UsingMSBuild() = [] member public this.``Single.Locations.Simple``() = - this.TestParameterInfoLocation("let a = System.Math.Sin($", 8) + this.TestParameterInfoLocation(""" +let a = System.Math.Sin($ +""", 8) [] member public this.``Single.Locations.LineWithSpaces``() = @@ -733,15 +759,21 @@ type UsingMSBuild() = [] member public this.``Single.Locations.WithNamespace``() = - this.TestParameterInfoLocation("let a = System.Threading.Interlocked.Exchange($", 8) + this.TestParameterInfoLocation(""" +let a = System.Threading.Interlocked.Exchange($ +""", 8) [] member public this.``ParameterInfo.Locations.WithoutNamespace``() = - this.TestParameterInfoLocation("let a = Interlocked.Exchange($", 8) + this.TestParameterInfoLocation(""" +let a = Interlocked.Exchange($ +""", 8) [] member public this.``Single.Locations.WithGenericArgs``() = - this.TestParameterInfoLocation("Interlocked.Exchange($", 0) + this.TestParameterInfoLocation(""" +Interlocked.Exchange($ +""", 0) [] member public this.``Single.Locations.FunctionWithSpace``() = @@ -772,7 +804,9 @@ type UsingMSBuild() = [] //This test verifies that ParamInfo location on a provided type without the namespace that exposes static parameter that takes >1 argument works normally. member public this.``TypeProvider.Type.ParameterInfoLocation.WithOutNamespace`` () = - this.TestParameterInfoLocation("open N1 \n"+"type boo = T<$", + this.TestParameterInfoLocation(""" +open N1 \n"+"type boo = T<$ +""", expectedPos = 11, addtlRefAssy = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) @@ -883,11 +917,14 @@ type UsingMSBuild() = let info = info.Value AssertEqual("f1", info.GetName(0)) // note about (5,0): service.fs adds three lines of empty text to the end of every file, so it reports the location of 'end of file' as first the char, 3 lines past the last line of the file - AssertEqual([|(2,10);(2,12);(2,13);(3,0)|], info.GetNoteworthyParamInfoLocations()) + AssertEqual([|(2,10);(2,12);(2,13);(2,0)|], info.GetNoteworthyParamInfoLocations()) [] member this.``LocationOfParams.AfterQuicklyTyping.CallConstructor``() = - let code = [ "type Foo() = class end" ] + let code = [ +""" +type Foo() = class end +""" ] let (_, _, file) = this.CreateSingleFileProject(code) TakeCoffeeBreak(this.VS) @@ -1052,7 +1089,10 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``Regression.LocationOfParams.Bug91479``() = - this.TestParameterInfoLocationOfParams("""let z = fun x -> x + ^System.Int16.Parse^(^$ """, markAtEOF=true) + this.TestParameterInfoLocationOfParams( +""" +let z = fun x -> x + ^System.Int16.Parse^(^$ +""", markAtEOF=true) [] member public this.``LocationOfParams.Attributes.Bug230393``() = @@ -1179,12 +1219,14 @@ We really need to rewrite some code paths here to use the real parse tree rather member public this.``LocationOfParams.BY_DESIGN.WayThatMismatchedParensFailOver.Case1``() = // when only one 'statement' after the mismatched parens after a comma, the comma swallows it and it becomes a badly-indented // continuation of the expression from the previous line - this.TestParameterInfoLocationOfParams(""" - type CC() = - member this.M(a,b,c,d) = a+b+c+d - let c = new CC() - ^c.M^(^1,^2,^3,^ $ - c.M(1,2,3,4)""", markAtEOF=true) + this.TestParameterInfoLocationOfParams( +""" +type CC() = + member this.M(a,b,c,d) = a+b+c+d +let c = new CC() +^c.M^(^1,^2,^3,^ $ +c.M(1,2,3,4) +""", markAtEOF=true) [] member public this.``LocationOfParams.BY_DESIGN.WayThatMismatchedParensFailOver.Case2``() = @@ -1200,14 +1242,16 @@ We really need to rewrite some code paths here to use the real parse tree rather // c.M(1,2,3,4) // c.M(1,2,3,4) // in r) - this.TestParameterInfoLocationOfParams(""" - type CC() = - member this.M(a,b,c,d) = a+b+c+d - let c = new CC() - ^c.M^(^1,2,3, $ - c.M(1,2,3,4) - c.M(1,2,3,4) - c.M(1,2,3,4)""", markAtEOF=true) + this.TestParameterInfoLocationOfParams( +""" +type CC() = + member this.M(a,b,c,d) = a+b+c+d +let c = new CC() +^c.M^(^1,2,3, $ +c.M(1,2,3,4) +c.M(1,2,3,4) +c.M(1,2,3,4) +""", markAtEOF=true) [] member public this.``LocationOfParams.Tuples.Bug91360.Case1``() = @@ -1221,13 +1265,15 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``LocationOfParams.Tuples.Bug123219``() = - this.TestParameterInfoLocationOfParams(""" - type Expr = | Num of int - type T<'a>() = - member this.M1(a:int*string, b:'a -> unit) = () - let x = new T() + this.TestParameterInfoLocationOfParams( +""" +type Expr = | Num of int +type T<'a>() = + member this.M1(a:int*string, b:'a -> unit) = () +let x = new T() - ^x.M1^(^(1,$ """, markAtEOF=true) +^x.M1^(^(1,$ +""", markAtEOF=true) [] member public this.``LocationOfParams.UnmatchedParens.Bug91609.OtherCases.Open``() = @@ -1535,43 +1581,55 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``LocationOfParams.TypeProviders.Prefix0``() = - this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts(""" - type U = ^N1.T^<^ $ """, // missing all params, just have < + this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts( +""" +type U = ^N1.T^<^ $ +""", // missing all params, just have < markAtEnd = true, additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) [] member public this.``LocationOfParams.TypeProviders.Prefix1``() = - this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts(""" - type U = ^N1.T^<^ "fo$o",^ 42 """, // missing > + this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts( +""" +type U = ^N1.T^<^ "fo$o",^ 42 +""", // missing > markAtEnd = true, additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) [] member public this.``LocationOfParams.TypeProviders.Prefix1Named``() = - this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts(""" - type U = ^N1.T^<^ "fo$o",^ ParamIgnored=42 """, // missing > + this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts( +""" +type U = ^N1.T^<^ "fo$o",^ ParamIgnored=42 +""", // missing > markAtEnd = true, additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) [] member public this.``LocationOfParams.TypeProviders.Prefix2``() = - this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts(""" - type U = ^N1.T^<^ "fo$o",^ """, // missing last param + this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts( +""" +type U = ^N1.T^<^ "fo$o",^ +""", // missing last param markAtEnd = true, additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) [] member public this.``LocationOfParams.TypeProviders.Prefix2Named1``() = - this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts(""" - type U = ^N1.T^<^ "fo$o",^ ParamIgnored= """, // missing last param after name with equals + this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts( +""" +type U = ^N1.T^<^ "fo$o",^ ParamIgnored= +""", // missing last param after name with equals markAtEnd = true, additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) [] member public this.``LocationOfParams.TypeProviders.Prefix2Named2``() = - this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts(""" - type U = ^N1.T^<^ "fo$o",^ ParamIgnored """, // missing last param after name sans equals + this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts( +""" +type U = ^N1.T^<^ "fo$o",^ ParamIgnored +""", // missing last param after name sans equals markAtEnd = true, additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]) @@ -1771,7 +1829,9 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``Multi.DotNet.StaticMethod.WithinLambda``() = - let fileContents = """let z = fun x -> x + System.Int16.Parse("",(*Mark*)""" + let fileContents = """ +let z = fun x -> x + System.Int16.Parse("",(*Mark*) +""" this.VerifyParameterInfoContainedAtStartOfMarker(fileContents,"(*Mark*)",["string";"System.Globalization.NumberStyles"]) [] @@ -1789,7 +1849,9 @@ We really need to rewrite some code paths here to use the real parse tree rather (* Common functions for multi-parameterinfo tests -------------------------------------------------- *) [] member public this.``Multi.DotNet.Constructor``() = - let fileContents = "let _ = new System.DateTime(2010,12,(*Mark*)" + let fileContents = """ +let _ = new System.DateTime(2010,12,(*Mark*) +""" this.VerifyParameterInfoContainedAtStartOfMarker(fileContents,"(*Mark*)",["int";"int";"int"]) [] @@ -1885,8 +1947,9 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``Multi.Function.WithOptionType``() = let fileContents = """ - let foo( a : int option, b : string ref) = 0 - let _ = foo(Some(12),(*Mark*)""" +let foo( a : int option, b : string ref) = 0 +let _ = foo(Some(12),(*Mark*) +""" this.VerifyParameterInfoAtStartOfMarker(fileContents,"(*Mark*)",[["int option";"string ref"]]) [] @@ -1901,8 +1964,9 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``Multi.Function.WithRefType``() = let fileContents = """ - let foo( a : int ref, b : string ref) = 0 - let _ = foo(ref 12,(*Mark*)""" +let foo( a : int ref, b : string ref) = 0 +let _ = foo(ref 12,(*Mark*) +""" this.VerifyParameterInfoAtStartOfMarker(fileContents,"(*Mark*)",[["int ref";"string ref"]]) (* Overload list/Adjust method's param for multi-parameterinfo tests ------------------------------ *) @@ -2057,17 +2121,18 @@ We really need to rewrite some code paths here to use the real parse tree rather [] member public this.``Regression.OptionalArguuments.Bug4042``() = - let fileContents = """ - module ParameterInfo - type TT(x : int, ?y : int) = - let z = y - do printfn "%A" z - member this.Foo(?z : int) = z + let fileContents =""" +module ParameterInfo +type TT(x : int, ?y : int) = + let z = y + do printfn "%A" z + member this.Foo(?z : int) = z - type TT2(x : int, y : int option) = - let z = y - do printfn "%A" z - let tt = TT((*Mark*)""" +type TT2(x : int, y : int option) = + let z = y + do printfn "%A" z +let tt = TT((*Mark*) +""" this.VerifyParameterInfoAtStartOfMarker(fileContents,"(*Mark*)",[["int";"int"]]) [] diff --git a/vsintegration/tests/UnitTests/SignatureHelpProviderTests.fs b/vsintegration/tests/UnitTests/SignatureHelpProviderTests.fs index ee651357715..11f08c1aa6b 100644 --- a/vsintegration/tests/UnitTests/SignatureHelpProviderTests.fs +++ b/vsintegration/tests/UnitTests/SignatureHelpProviderTests.fs @@ -125,8 +125,10 @@ type foo5 = N1.T ("type foo5 = N1.T + @@ -242,10 +243,6 @@ - - - -