提交 19f18530 编写于 作者: V Vasily Kirichenko 提交者: Will Smith

Fix ServiceAssemblyContent for symbols from modules with auto added "Module" suffix (#4102)

* fix ServiceAssemblyContent for symbols from modules with auto added "Module" suffix

* add tests

* correct a test

* improve the tests
上级 518e59be
......@@ -157,10 +157,10 @@ type Parent =
else ident)
let removeModuleSuffix (idents: Idents) =
if entity.IsFSharpModule && idents.Length > 0 && Symbol.hasModuleSuffixAttribute entity then
if entity.IsFSharpModule && idents.Length > 0 then
let lastIdent = idents.[idents.Length - 1]
if lastIdent.EndsWith "Module" then
idents |> Array.replace (idents.Length - 1) (lastIdent.Substring(0, lastIdent.Length - 6))
if lastIdent <> entity.DisplayName then
idents |> Array.replace (idents.Length - 1) entity.DisplayName
else idents
else idents
......@@ -275,7 +275,7 @@ module AssemblyContentProvider =
| false, _ -> None
WithModuleSuffix =
if entity.IsFSharpModule && Symbol.hasModuleSuffixAttribute entity then
if entity.IsFSharpModule && (Symbol.hasModuleSuffixAttribute entity || entity.CompiledName <> entity.DisplayName) then
currentEntity |> Option.map (fun e -> e.CleanedIdents)
else parent.WithModuleSuffix
......
#if INTERACTIVE
#r "../../Debug/fcs/net45/FSharp.Compiler.Service.dll" // note, run 'build fcs debug' to generate this, this DLL has a public API so can be used from F# Interactive
#r "../../packages/NUnit.3.5.0/lib/net45/nunit.framework.dll"
#load "FsUnit.fs"
#load "Common.fs"
#else
module Tests.Service.AssemblyContentProviderTests
#endif
open System
open System.IO
open System.Text
open NUnit.Framework
open Microsoft.FSharp.Compiler.SourceCodeServices
let private filePath = "C:\\test.fs"
let private projectOptions : FSharpProjectOptions =
{ ProjectFileName = "C:\\test.fsproj"
SourceFiles = [| filePath |]
ReferencedProjects = [| |]
OtherOptions = [| |]
IsIncompleteTypeCheckEnvironment = true
UseScriptResolutionRules = false
LoadTime = DateTime.MaxValue
OriginalLoadReferences = []
UnresolvedReferences = None
ExtraProjectInfo = None
Stamp = None }
let private checker = FSharpChecker.Create()
let (=>) (source: string) (expected: string list) =
let lines =
use reader = new StringReader(source)
[| let line = ref (reader.ReadLine())
while not (isNull !line) do
yield !line
line := reader.ReadLine()
if source.EndsWith "\n" then
// last trailing space not returned
// http://stackoverflow.com/questions/19365404/stringreader-omits-trailing-linebreak
yield "" |]
let _, checkFileAnswer = checker.ParseAndCheckFileInProject(filePath, 0, source, projectOptions) |> Async.RunSynchronously
let checkFileResults =
match checkFileAnswer with
| FSharpCheckFileAnswer.Aborted -> failwithf "ParseAndCheckFileInProject aborted"
| FSharpCheckFileAnswer.Succeeded(checkFileResults) -> checkFileResults
let actual =
AssemblyContentProvider.getAssemblySignatureContent AssemblyContentType.Full checkFileResults.PartialAssemblySignature
|> List.map (fun x -> x.CleanedIdents |> String.concat ".")
|> List.sort
let expected = List.sort expected
if actual <> expected then failwithf "\n\nExpected\n\n%A\n\nbut was\n\n%A" expected actual
[<Test>]
let ``implicitly added Module suffix is removed``() =
"""
type MyType = { F: int }
module MyType =
let func123 x = x
"""
=> ["Test"
"Test.MyType"
"Test.MyType"
"Test.MyType.func123"]
[<Test>]
let ``Module suffix added by an xplicitly applied MuduleSuffix attribute is removed``() =
"""
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module MyType =
let func123 x = x
"""
=> [ "Test"
"Test.MyType"
"Test.MyType.func123" ]
......@@ -94,6 +94,9 @@
<Compile Include="..\..\..\tests\service\StructureTests.fs">
<Link>StructureTests.fs</Link>
</Compile>
<Compile Include="..\..\..\tests\service\AssemblyContentProviderTests.fs">
<Link>AssemblyContentProviderTests.fs</Link>
</Compile>
<Compile Include="UnusedOpensTests.fs">
<Link>ServiceAnalysis\UnusedOpensTests.fs</Link>
</Compile>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册