Skip to content

Commit 2255f4c

Browse files
authored
add ProjectViewer (#50)
use `ProjectViewer.Render` to get shown source files skip known failure on OS X
1 parent a534dcb commit 2255f4c

File tree

7 files changed

+312
-38
lines changed

7 files changed

+312
-38
lines changed

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Dotnet.ProjInfo.Workspace.Tests",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
"program": "${workspaceFolder}/test/Dotnet.ProjInfo.Workspace.Tests/bin/Debug/netcoreapp2.1/Dotnet.ProjInfo.Workspace.Tests.dll",
13+
"args": [],
14+
"cwd": "${workspaceFolder}",
15+
"stopAtEntry": false,
16+
"console": "internalConsole"
17+
}
18+
19+
]
20+
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"tasks": [
99
{
1010
"taskName": "build",
11-
"args": [ "src/dotnet-proj" ],
11+
"args": [ "src/dotnet-proj.sln" ],
1212
"isBuildCommand": true,
1313
"showOutput": "silent",
1414
"problemMatcher": "$msCompile"

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project ToolsVersion="15.0">
22

33
<PropertyGroup>
4-
<Version Condition=" '$(Version)' == '' ">0.33.0$(VersionSuffix)</Version>
4+
<Version Condition=" '$(Version)' == '' ">0.34.0$(VersionSuffix)</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/Dotnet.ProjInfo.Workspace/Library.fs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ type Loader private (msbuildPath, msbuildNetSdkPath) =
8686
Error (GetProjectOptionsErrors.GenericError(proj, "not found"))
8787

8888
match loader notify cache project with
89-
| Ok (po, sources, props, additionalProjs) ->
90-
// TODO sources and props are wrong, because not project specific. but of root proj
91-
let loaded po = WorkspaceProjectState.Loaded (po, sources, props)
92-
89+
| Ok (po, props, additionalProjs) ->
9390
let rec visit (p: ProjectOptions) = seq {
9491
yield p
9592
for p2pRef in p.ReferencedProjects do
@@ -102,7 +99,8 @@ type Loader private (msbuildPath, msbuildNetSdkPath) =
10299
parsedProjects.AddOrUpdate(getKey proj, proj, fun _ _ -> proj) |> ignore
103100

104101
for proj in visit po do
105-
notify (loaded proj)
102+
WorkspaceProjectState.Loaded (proj, props)
103+
|> notify
106104

107105
| Error e ->
108106
let failed = WorkspaceProjectState.Failed (project, e)
@@ -163,3 +161,39 @@ type NetFWInfo private (msbuildPath) =
163161

164162
static member Create(config: NetFWInfoConfig) =
165163
NetFWInfo(config.MSBuildHost)
164+
165+
type ProjectViewerTree =
166+
{ Name: string;
167+
Items: ProjectViewerItem list }
168+
and [<RequireQualifiedAccess>] ProjectViewerItem =
169+
| Compile of string
170+
171+
type ProjectViewer () =
172+
173+
member __.Render(proj: ProjectOptions) =
174+
175+
let compileFiles =
176+
let sources = proj.SourceFiles
177+
match proj.ExtraProjectInfo.ProjectSdkType with
178+
| ProjectSdkType.Verbose _ ->
179+
//compatibility with old behaviour (projectcracker), so test output is exactly the same
180+
//the temp source files (like generated assemblyinfo.fs) are not added to sources
181+
let isTempFile (name: string) =
182+
let tempPath = Path.GetTempPath()
183+
let s = name.ToLower()
184+
s.StartsWith(tempPath.ToLower())
185+
sources
186+
|> List.filter (fun p -> not(isTempFile p))
187+
| ProjectSdkType.DotnetSdk _ ->
188+
//the generated assemblyinfo.fs are not shown as sources
189+
let isGeneratedAssemblyinfo (name: string) =
190+
let projName = proj.ProjectFileName |> Path.GetFileNameWithoutExtension
191+
//TODO check is in `obj` dir for the tfm
192+
//TODO better, get the name from fsproj
193+
//TODO cs too
194+
name.EndsWith(sprintf "%s.AssemblyInfo.fs" projName)
195+
sources
196+
|> List.filter (fun p -> not(isGeneratedAssemblyinfo p))
197+
198+
{ ProjectViewerTree.Name = proj.ProjectFileName |> Path.GetFileNameWithoutExtension
199+
Items = compileFiles |> List.map ProjectViewerItem.Compile }

src/Dotnet.ProjInfo.Workspace/ProjectCrackerDotnetSdk.fs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ module ProjectCrackerDotnetSdk =
229229

230230
let isSourceFile : (string -> bool) =
231231
if Path.GetExtension(file) = ".fsproj" then
232-
(fun n -> n.EndsWith ".fs" || n.EndsWith ".fsx" || n.EndsWith ".fsi")
232+
FscArguments.isCompileFile
233233
else
234234
(fun n -> n.EndsWith ".cs")
235235

@@ -288,25 +288,7 @@ module ProjectCrackerDotnetSdk =
288288
try
289289
let po, log, additionalProjs = getProjectOptionsFromProjectFile msbuildPath notifyState cache parseAsSdk file
290290

291-
let compileFiles =
292-
let sources = FscArguments.compileFiles po.OtherOptions
293-
match po with
294-
| ProjectExtraInfoBySdk extraInfo ->
295-
match extraInfo.ProjectSdkType with
296-
| ProjectSdkType.Verbose _ ->
297-
//compatibility with old behaviour (projectcracker), so test output is exactly the same
298-
//the temp source files (like generated assemblyinfo.fs) are not added to sources
299-
let isTempFile (name: string) =
300-
let tempPath = Path.GetTempPath()
301-
let s = name.ToLower()
302-
s.StartsWith(tempPath.ToLower())
303-
sources
304-
|> List.filter (not << isTempFile)
305-
| ProjectSdkType.DotnetSdk _ ->
306-
sources
307-
| _ -> sources
308-
309-
Ok (po, Seq.toList compileFiles, (log |> Map.ofList), additionalProjs)
291+
Ok (po, (log |> Map.ofList), additionalProjs)
310292
with
311293
| ProjectInspectException d -> Error d
312294
| e -> Error (GenericError(file, e.Message))

src/Dotnet.ProjInfo.Workspace/ProjectCrackerTypes.fs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ and ProjectReference =
7676

7777
type [<RequireQualifiedAccess>] WorkspaceProjectState =
7878
| Loading of string * ((string * string) list)
79-
| Loaded of ProjectOptions * string list * Map<string,string>
79+
| Loaded of ProjectOptions * Map<string,string>
8080
| Failed of string * GetProjectOptionsErrors
8181

8282
module ProjectRecognizer =
@@ -128,11 +128,8 @@ module FscArguments =
128128
|> Option.map (makeAbs projDir)
129129

130130
let isCompileFile (s:string) =
131-
s.EndsWith(".fs") || s.EndsWith (".fsi")
132-
133-
let compileFiles =
134-
//TODO filter the one without initial -
135-
List.filter isCompileFile
131+
//TODO check if is not an option, check prefix `-` ?
132+
s.EndsWith(".fs") || s.EndsWith (".fsi") || s.EndsWith (".fsx")
136133

137134
let references =
138135
//TODO valid also --reference:

0 commit comments

Comments
 (0)