Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit19f1853

Browse files
vasily-kirichenkoTIHan
authored andcommitted
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
1 parent518e59b commit19f1853

File tree

3 files changed

+92
-4
lines changed

3 files changed

+92
-4
lines changed

‎src/fsharp/service/ServiceAssemblyContent.fs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ type Parent =
157157
else ident)
158158

159159
letremoveModuleSuffix(idents:Idents)=
160-
if entity.IsFSharpModule&& idents.Length>0&& Symbol.hasModuleSuffixAttribute entitythen
160+
if entity.IsFSharpModule&& idents.Length>0then
161161
letlastIdent= idents.[idents.Length-1]
162-
if lastIdent.EndsWith"Module"then
163-
idents|> Array.replace(idents.Length-1)(lastIdent.Substring(0, lastIdent.Length-6))
162+
if lastIdent<> entity.DisplayNamethen
163+
idents|> Array.replace(idents.Length-1)entity.DisplayName
164164
else idents
165165
else idents
166166

@@ -275,7 +275,7 @@ module AssemblyContentProvider =
275275
|false,_-> None
276276

277277
WithModuleSuffix=
278-
if entity.IsFSharpModule&& Symbol.hasModuleSuffixAttribute entitythen
278+
if entity.IsFSharpModule&&(Symbol.hasModuleSuffixAttribute entity|| entity.CompiledName<> entity.DisplayName)then
279279
currentEntity|> Option.map(fun e-> e.CleanedIdents)
280280
else parent.WithModuleSuffix
281281

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#if INTERACTIVE
2+
#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
3+
#r"../../packages/NUnit.3.5.0/lib/net45/nunit.framework.dll"
4+
#load"FsUnit.fs"
5+
#load"Common.fs"
6+
#else
7+
moduleTests.Service.AssemblyContentProviderTests
8+
#endif
9+
10+
openSystem
11+
openSystem.IO
12+
openSystem.Text
13+
openNUnit.Framework
14+
openMicrosoft.FSharp.Compiler.SourceCodeServices
15+
16+
letprivatefilePath="C:\\test.fs"
17+
18+
letprivateprojectOptions:FSharpProjectOptions=
19+
{ ProjectFileName="C:\\test.fsproj"
20+
SourceFiles=[| filePath|]
21+
ReferencedProjects=[||]
22+
OtherOptions=[||]
23+
IsIncompleteTypeCheckEnvironment=true
24+
UseScriptResolutionRules=false
25+
LoadTime= DateTime.MaxValue
26+
OriginalLoadReferences=[]
27+
UnresolvedReferences= None
28+
ExtraProjectInfo= None
29+
Stamp= None}
30+
31+
letprivatechecker= FSharpChecker.Create()
32+
33+
let(=>)(source: string)(expected: string list)=
34+
letlines=
35+
use reader=new StringReader(source)
36+
[|letline= ref(reader.ReadLine())
37+
whilenot(isNull!line)do
38+
yield!line
39+
line:= reader.ReadLine()
40+
if source.EndsWith"\n"then
41+
// last trailing space not returned
42+
// http://stackoverflow.com/questions/19365404/stringreader-omits-trailing-linebreak
43+
yield""|]
44+
45+
let_,checkFileAnswer= checker.ParseAndCheckFileInProject(filePath,0, source, projectOptions)|> Async.RunSynchronously
46+
47+
letcheckFileResults=
48+
match checkFileAnswerwith
49+
| FSharpCheckFileAnswer.Aborted-> failwithf"ParseAndCheckFileInProject aborted"
50+
| FSharpCheckFileAnswer.Succeeded(checkFileResults)-> checkFileResults
51+
52+
letactual=
53+
AssemblyContentProvider.getAssemblySignatureContent AssemblyContentType.Full checkFileResults.PartialAssemblySignature
54+
|> List.map(fun x-> x.CleanedIdents|> String.concat".")
55+
|> List.sort
56+
57+
letexpected= List.sort expected
58+
59+
if actual<> expectedthen failwithf"\n\nExpected\n\n%A\n\nbut was\n\n%A" expected actual
60+
61+
[<Test>]
62+
let``implicitly added Module suffix is removed``()=
63+
"""
64+
type MyType = { F: int }
65+
66+
module MyType =
67+
let func123 x = x
68+
"""
69+
=>["Test"
70+
"Test.MyType"
71+
"Test.MyType"
72+
"Test.MyType.func123"]
73+
74+
[<Test>]
75+
let``Module suffix added by an xplicitly applied MuduleSuffix attribute is removed``()=
76+
"""
77+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
78+
module MyType =
79+
let func123 x = x
80+
"""
81+
=>["Test"
82+
"Test.MyType"
83+
"Test.MyType.func123"]
84+
85+

‎vsintegration/tests/unittests/VisualFSharp.UnitTests.fsproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
<CompileInclude="..\..\..\tests\service\StructureTests.fs">
9595
<Link>StructureTests.fs</Link>
9696
</Compile>
97+
<CompileInclude="..\..\..\tests\service\AssemblyContentProviderTests.fs">
98+
<Link>AssemblyContentProviderTests.fs</Link>
99+
</Compile>
97100
<CompileInclude="UnusedOpensTests.fs">
98101
<Link>ServiceAnalysis\UnusedOpensTests.fs</Link>
99102
</Compile>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp