Skip to content

Commit 1dc8bde

Browse files
committed
Add CompileItem metadata to types
1 parent 4220188 commit 1dc8bde

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/Ionide.ProjInfo/Library.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ module ProjectLoader =
742742
Name = name
743743
FullPath = fullPath
744744
Link = link
745+
Metadata =
746+
p.Metadata
747+
|> Seq.map (fun pm -> pm.Name, pm.EvaluatedValue)
748+
|> Map.ofSeq
745749
}
746750
)
747751

@@ -1587,7 +1591,7 @@ module ProjectViewer =
15871591
sources
15881592
|> List.choose (
15891593
function
1590-
| ProjectItem.Compile(name, fullPath) -> Some(name, fullPath)
1594+
| ProjectItem.Compile(name, fullPath, _) -> Some(name, fullPath)
15911595
)
15921596
|> List.filter (fun (_, p) -> includeSourceFile p)
15931597

src/Ionide.ProjInfo/Types.fs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Types =
4848
| Exe
4949
| Custom of string
5050

51-
type ProjectItem = Compile of name: string * fullpath: string
51+
type ProjectItem = Compile of name: string * fullpath: string * metadata: Map<string, string> option
5252

5353
type ProjectOptions = {
5454
ProjectId: string option
@@ -75,10 +75,37 @@ module Types =
7575
member x.ResolvedTargetPath =
7676
defaultArg x.TargetRefPath x.TargetPath
7777

78+
/// Represents a `<Compile>` node within an fsproj file.
7879
type CompileItem = {
80+
/// The `Compile` node's Include contents, after MSBuild has finished evaluation.
81+
/// For example:
82+
/// * `<Compile Include="Foo.fs"/>` would have this set to "Foo.fs";
83+
/// * `<Compile Include="Bar/Baz.fs"/>` would have `"Bar/Baz.fs"`;
84+
/// * (contrived): `<Compile Include="$(IsPackable).fs"/>` might have `true.fs` or `false.fs`, for example.
7985
Name: string
86+
/// Full path on disk to the F# file this `Compile` node is telling MsBuild to compile.
8087
FullPath: string
88+
/// Value of the `<Link />` sub-node, if one exists.
89+
/// For example, `<Compile Include="Foo.fs"><Link>../bar.fs</Link></Compile` would set this to
90+
/// "../bar.fs" (no further path resolution takes place).
8191
Link: string option
92+
/// All the other metadata in the project file associated with this Compile node.
93+
/// This is a map of "name of metadata key" to "contents of that key".
94+
/// Recall that according to MsBuild, those contents are not actually unrestricted XML, although they sure do look like it!
95+
/// If you try and put XML as a metadata value, MsBuild will just give it to you as a string, or will fail to load the
96+
/// project at all.
97+
///
98+
/// For example:
99+
/// * `<Compile Include="Foo.fs"><Something>hello</Something></Compile>` sets the metadata value "Something" -> "hello".
100+
/// * `<Compile Include="Foo.fs"><Blah Baz="hi" /></Compile>` fails at project load time.
101+
/// * `<Compile Include="Foo.fs"><Blah></Blah></Compile>` sets the metadata value "Blah" to the empty string.
102+
/// * `<Compile Include="Foo.fs"><Blah><Quux></Quux></Blah></Compile>` sets the metadata value "Blah" to the string "<Quux></Quux>".
103+
///
104+
/// This list includes the `Link` value, if it exists, which was also extracted for convenience into the `Link` field
105+
/// of this CompileItem.
106+
///
107+
/// If you specify the same metadata key multiple times, the last value wins. (This is MsBuild's decision, not ours.)
108+
Metadata: Map<string, string>
82109
}
83110

84111
type ToolsPath = ToolsPath of string

src/Ionide.ProjInfo/VisualTree.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ module VisualTree =
7575
projPath
7676
|> getVisualPath None (Some sourceFile) sourceFile
7777

78-
ProjectItem.Compile(name, fullpath)
78+
ProjectItem.Compile(name, fullpath, None)
7979
| Some p ->
8080

8181
let (name, fullpath) =
8282
projPath
8383
|> getVisualPath p.Link (Some p.FullPath) p.Name
8484

85-
ProjectItem.Compile(name, fullpath)
85+
ProjectItem.Compile(name, fullpath, Some p.Metadata)

0 commit comments

Comments
 (0)