Skip to content

Commit 45d0ebf

Browse files
Krzysztof-Cieslakenricosada
authored andcommitted
Update FSC to 29.0 (#386)
### update FSC to 29.0 update FSC to v29.0 Notes about tests changes: in `MultipleUnsavedFiles` integration test the error hint `addTwo2` should be valid suggestion need to check if is a FCS regression or in FSAC the `Test1Json` integration test it's now flaky (disabled it), the `Range` sometimes finish at start of next line other times at end of current line like ```diff "Range": { "StartColumn": 1, "StartLine": 1, - "EndColumn": 1, - "EndLine": 16 + "EndColumn": 6, + "EndLine": 15 }, ``` ### update FSharpLint.Core update FSharpLint.Core to v0.12.1 support fsharplint xml and json configs workaround fsharplint message change. The message format returned by linter is `FS01234: info text"` , so need to strip the warning code from output message NOTE in the test `LinterWithOptions` the xmlconfig is read and converted, but hints are not disabled. Changed the test, based on current fsharplint behaviour
1 parent 806bf69 commit 45d0ebf

File tree

8 files changed

+489
-293
lines changed

8 files changed

+489
-293
lines changed

build.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ let isTestSkipped cfg (fn: string) =
4848
| _, _, "OldSdk", "InvalidProjectFileRunner.fsx" when isMono ->
4949
Some "known difference. On mono the error message from msbuild is different and not normalized"
5050
// stdio and http
51+
| _, _, "Test1Json", "Test1JsonRunner.fsx" ->
52+
Some "flaky, the Range sometimes finish at start of newline other times at end of line"
5153
| _, _, "ProjectCache", "Runner.fsx" ->
5254
Some "fails, ref https://github.com/fsharp/FsAutoComplete/issues/198"
5355
| _, _, "DotNetSdk2.0CrossgenWithNetFx", "Runner.fsx" ->

paket.dependencies

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ storage: none
77
github Microsoft/visualfsharp:Visual-Studio-2017-Version-15.4 src/fsharp/FSharp.Build/Fsc.fs
88

99
nuget Argu ~> 5.2.0
10-
nuget FSharp.Compiler.Service ~> 28.0
11-
nuget FSharp.Compiler.Service.ProjectCracker ~> 28.0 framework:net461, condition:net461
10+
nuget FSharp.Compiler.Service ~> 29.0
11+
nuget FSharp.Compiler.Service.ProjectCracker ~> 29.0 framework:net461, condition:net461
1212
nuget Dotnet.ProjInfo ~> 0.31.0
1313
nuget FSharp.Data 3.0.1
1414
nuget ICSharpCode.Decompiler 3.2.0.3856
1515
nuget Sln ~> 0.3.0
1616
nuget Mono.Cecil >= 0.10.0-beta7
1717
nuget Newtonsoft.Json
1818
nuget Suave
19-
nuget FSharpLint.Core 0.10.8
19+
nuget FSharpLint.Core 0.12.1
2020
nuget FSharp.Core redirects:force
2121
nuget OptimizedPriorityQueue
2222
nuget System.ValueTuple redirects:force, condition:net461 // workaround for older version of net framework..

paket.lock

Lines changed: 261 additions & 280 deletions
Large diffs are not rendered by default.

src/FsAutoComplete.Core/Commands.fs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ type Commands (serialize : Serializer) =
7171

7272
let checker = FSharpCompilerServiceChecker()
7373
let state = State.Initial
74-
let fsharpLintConfig = ConfigurationManager.ConfigurationManager()
7574
let fileParsed = Event<FSharpParseFileResults>()
7675
let fileChecked = Event<ParseAndCheckResults * string * int>()
7776
let mutable notifyErrorsInBackground = true
@@ -721,11 +720,46 @@ type Commands (serialize : Serializer) =
721720
| None -> [ CoreResponse.InfoRes "Something went wrong during parsing"]
722721
| Some tree ->
723722
try
724-
fsharpLintConfig.LoadConfigurationForProject file
725-
let opts = fsharpLintConfig.GetConfigurationForProject (file)
726-
let res =
723+
let loadXmlConfig projectFilePath =
724+
match FSharpLint.Application.XmlConfiguration.tryLoadConfigurationForProject projectFilePath with
725+
| None -> Result.Ok None
726+
| Some xmlConfig ->
727+
{ ConfigurationManager.Configuration.conventions = xmlConfig |> FSharpLint.Application.XmlConfiguration.convertConventions
728+
ConfigurationManager.Configuration.formatting = xmlConfig |> FSharpLint.Application.XmlConfiguration.convertFormatting
729+
ConfigurationManager.Configuration.hints = xmlConfig |> FSharpLint.Application.XmlConfiguration.convertHints
730+
ConfigurationManager.Configuration.ignoreFiles = xmlConfig |> FSharpLint.Application.XmlConfiguration.convertIgnoreFiles
731+
ConfigurationManager.Configuration.typography = xmlConfig |> FSharpLint.Application.XmlConfiguration.convertTypography }
732+
|> Some
733+
|> Result.Ok
734+
let loadJsonConfig projectFilePath =
735+
match FSharpLint.Application.ConfigurationManagement.loadConfigurationForProject projectFilePath with
736+
| ConfigurationManagement.ConfigurationResult.Success config ->
737+
Result.Ok config
738+
| ConfigurationManagement.ConfigurationResult.Failure errors ->
739+
Result.Error errors
740+
let fsharpLintConfig =
741+
// first we check if exists xml config (backward compatibility)
742+
// after that if exists json config
743+
match loadXmlConfig file with
744+
| Result.Ok (Some config) ->
745+
Result.Ok config
746+
| Result.Ok None
747+
| Result.Error _ ->
748+
//TODO log xml config error
749+
match loadJsonConfig file with
750+
| Result.Ok config ->
751+
Result.Ok config
752+
| Result.Error e ->
753+
Result.Error e
754+
755+
let opts =
756+
match fsharpLintConfig with
757+
| Result.Ok config -> Some config
758+
| Result.Error _ -> None
759+
760+
let res =
727761
Lint.lintParsedSource
728-
{ Lint.OptionalLintParameters.Default with Configuration = Some opts}
762+
{ Lint.OptionalLintParameters.Default with Configuration = opts}
729763
{ Ast = tree
730764
Source = source
731765
TypeCheckResults = Some tyRes.GetCheckResults }

src/FsAutoComplete.Core/CompilerServiceInterface.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open FSharp.Compiler.SourceCodeServices
66
open Utils
77
open FSharp.Compiler.Range
88
open FSharp.Compiler
9+
open FSharp.Compiler.Text
910

1011
[<RequireQualifiedAccess>]
1112
type FindDeclarationResult =
@@ -487,7 +488,7 @@ type FSharpCompilerServiceChecker() =
487488
])
488489

489490
member __.GetProjectOptionsFromScript(file, source) = async {
490-
491+
let source = SourceText.ofString source
491492
#if SCRIPT_REFS_FROM_MSBUILD
492493

493494
let targetFramework = NETFrameworkInfoProvider.netReferencesAssembliesTFMLatest ()
@@ -539,11 +540,13 @@ type FSharpCompilerServiceChecker() =
539540

540541
member __.ParseFile(fn, source, fpo) =
541542
logDebug "[Checker] ParseFile - %s" fn
543+
let source = SourceText.ofString source
542544
checker.ParseFile(fn, source, fpo)
543545

544546
member __.ParseAndCheckFileInProject(filePath, version, source, options) =
545547
async {
546548
logDebug "[Checker] ParseAndCheckFileInProject - %s" filePath
549+
let source = SourceText.ofString source
547550
let options = clearProjectReferecnes options
548551
let fixedFilePath = fixFileName filePath
549552
let! res = Async.Catch (checker.ParseAndCheckFileInProject (fixedFilePath, version, source, options, null))
@@ -561,6 +564,7 @@ type FSharpCompilerServiceChecker() =
561564
member __.ParseAndCheckFileInProject'(filePath, version, source, options) =
562565
async {
563566
logDebug "[Checker] ParseAndCheckFileInProject2 - %s" filePath
567+
let source = SourceText.ofString source
564568
let options = clearProjectReferecnes options
565569
let fixedFilePath = fixFileName filePath
566570
let! res = Async.Catch (checker.ParseAndCheckFileInProject (fixedFilePath, version, source, options, null))
@@ -575,8 +579,9 @@ type FSharpCompilerServiceChecker() =
575579

576580
member __.TryGetRecentCheckResultsForFile(file, options, ?source) =
577581
logDebug "[Checker] TryGetRecentCheckResultsForFile - %s" file
582+
let source = source |> Option.map SourceText.ofString
578583
let options = clearProjectReferecnes options
579-
checker.TryGetRecentCheckResultsForFile(file, options, ?source=source)
584+
checker.TryGetRecentCheckResultsForFile(file, options, ?sourceText=source)
580585
|> Option.map (fun (pr, cr, _) -> ParseAndCheckResults (pr, cr, entityCache))
581586

582587
member x.GetUsesOfSymbol (file, options : (SourceFilePath * FSharpProjectOptions) seq, symbol : FSharpSymbol) = async {
@@ -599,6 +604,7 @@ type FSharpCompilerServiceChecker() =
599604

600605
member __.GetDeclarations (fileName, source, options, version) = async {
601606
logDebug "[Checker] GetDeclarations - %s" fileName
607+
let source = SourceText.ofString source
602608
let! parseResult = checker.ParseFile(fileName, source, options)
603609
return parseResult.GetNavigationItems().Declarations
604610
}

src/FsAutoComplete/CommandResponse.fs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,19 @@ module CommandResponse =
683683
serialize { Kind = kind; Data = data }
684684

685685
let lint (serialize : Serializer) (warnings : LintWarning.Warning list) =
686-
let data = warnings |> List.toArray
686+
687+
/// strip the fsharp lint warning code, in the format `FS01234: info"`
688+
let removeLinterCode (s: string) =
689+
let index = s.IndexOf(":")
690+
if index > 0 && (index + 2) < s.Length then
691+
s.Substring(index + 2)
692+
else
693+
s
694+
695+
let data =
696+
warnings
697+
|> List.map (fun w -> { w with Info = removeLinterCode w.Info })
698+
|> List.toArray
687699

688700
serialize { Kind = "lint"; Data = data }
689701

test/FsAutoComplete.IntegrationTests/LinterWithOptions/output.json

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,168 @@
1111
}
1212
{
1313
"Kind": "lint",
14-
"Data": []
14+
"Data": [
15+
{
16+
"Info": "`not (a <> b)` might be able to be refactored into `a = b`.",
17+
"Range": {
18+
"StartColumn": 17,
19+
"StartLine": 2,
20+
"EndColumn": 27,
21+
"EndLine": 2
22+
},
23+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
24+
"Fix": {
25+
"FromText": "not (a<>b)",
26+
"FromRange": {
27+
"StartColumn": 17,
28+
"StartLine": 2,
29+
"EndColumn": 27,
30+
"EndLine": 2
31+
},
32+
"ToText": "a = b"
33+
}
34+
},
35+
{
36+
"Info": "`fun x -> x` might be able to be refactored into `id`.",
37+
"Range": {
38+
"StartColumn": 13,
39+
"StartLine": 3,
40+
"EndColumn": 23,
41+
"EndLine": 3
42+
},
43+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
44+
"Fix": {
45+
"FromText": "fun a -> a",
46+
"FromRange": {
47+
"StartColumn": 13,
48+
"StartLine": 3,
49+
"EndColumn": 23,
50+
"EndLine": 3
51+
},
52+
"ToText": "id"
53+
}
54+
},
55+
{
56+
"Info": "`not true` might be able to be refactored into `false`.",
57+
"Range": {
58+
"StartColumn": 13,
59+
"StartLine": 4,
60+
"EndColumn": 21,
61+
"EndLine": 4
62+
},
63+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
64+
"Fix": {
65+
"FromText": "not true",
66+
"FromRange": {
67+
"StartColumn": 13,
68+
"StartLine": 4,
69+
"EndColumn": 21,
70+
"EndLine": 4
71+
},
72+
"ToText": "false"
73+
}
74+
},
75+
{
76+
"Info": "`not false` might be able to be refactored into `true`.",
77+
"Range": {
78+
"StartColumn": 13,
79+
"StartLine": 5,
80+
"EndColumn": 22,
81+
"EndLine": 5
82+
},
83+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
84+
"Fix": {
85+
"FromText": "not false",
86+
"FromRange": {
87+
"StartColumn": 13,
88+
"StartLine": 5,
89+
"EndColumn": 22,
90+
"EndLine": 5
91+
},
92+
"ToText": "true"
93+
}
94+
},
95+
{
96+
"Info": "`a <> true` might be able to be refactored into `not a`.",
97+
"Range": {
98+
"StartColumn": 15,
99+
"StartLine": 7,
100+
"EndColumn": 22,
101+
"EndLine": 7
102+
},
103+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
104+
"Fix": {
105+
"FromText": "a<>true",
106+
"FromRange": {
107+
"StartColumn": 15,
108+
"StartLine": 7,
109+
"EndColumn": 22,
110+
"EndLine": 7
111+
},
112+
"ToText": "not a"
113+
}
114+
},
115+
{
116+
"Info": "`List.head (List.sort x)` might be able to be refactored into `List.min x`.",
117+
"Range": {
118+
"StartColumn": 15,
119+
"StartLine": 9,
120+
"EndColumn": 38,
121+
"EndLine": 9
122+
},
123+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
124+
"Fix": {
125+
"FromText": "List.head (List.sort a)",
126+
"FromRange": {
127+
"StartColumn": 15,
128+
"StartLine": 9,
129+
"EndColumn": 38,
130+
"EndLine": 9
131+
},
132+
"ToText": "List.min a"
133+
}
134+
},
135+
{
136+
"Info": "`x = null` might be able to be refactored into `isNull x`.",
137+
"Range": {
138+
"StartColumn": 15,
139+
"StartLine": 8,
140+
"EndColumn": 21,
141+
"EndLine": 8
142+
},
143+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
144+
"Fix": {
145+
"FromText": "a=null",
146+
"FromRange": {
147+
"StartColumn": 15,
148+
"StartLine": 8,
149+
"EndColumn": 21,
150+
"EndLine": 8
151+
},
152+
"ToText": "isNull a"
153+
}
154+
},
155+
{
156+
"Info": "`not (a = b)` might be able to be refactored into `a <> b`.",
157+
"Range": {
158+
"StartColumn": 17,
159+
"StartLine": 1,
160+
"EndColumn": 26,
161+
"EndLine": 1
162+
},
163+
"Input": "let test1 a b = not (a=b)\nlet test2 a b = not (a<>b)\nlet test3 = fun a -> a\nlet test4 = not true\nlet test5 = not false\nlet test6 = List.fold ( + ) 0\nlet test7 a = a<>true\nlet test8 a = a=null\nlet test9 a = List.head (List.sort a)\n",
164+
"Fix": {
165+
"FromText": "not (a=b)",
166+
"FromRange": {
167+
"StartColumn": 17,
168+
"StartLine": 1,
169+
"EndColumn": 26,
170+
"EndLine": 1
171+
},
172+
"ToText": "a <> b"
173+
}
174+
}
175+
]
15176
}
16177
{
17178
"Kind": "info",

test/FsAutoComplete.IntegrationTests/MultipleUnsavedFiles/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"StartColumn": 23,
7474
"EndColumn": 29,
7575
"Severity": "Error",
76-
"Message": "The value, constructor, namespace or type 'addTwo' is not defined. Maybe you want one of the following:\n addTwo2",
76+
"Message": "The value, constructor, namespace or type 'addTwo' is not defined.",
7777
"Subcategory": "typecheck"
7878
}
7979
]

0 commit comments

Comments
 (0)