Skip to content

Commit

Permalink
Add CompileItem metadata to types
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug123 authored and TheAngryByrd committed Oct 2, 2024
1 parent 4220188 commit f789e71
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Ionide.ProjInfo/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,10 @@ module ProjectLoader =
Name = name
FullPath = fullPath
Link = link
Metadata =
p.Metadata
|> Seq.map (fun pm -> pm.Name, pm.EvaluatedValue)
|> Map.ofSeq
}
)

Expand Down Expand Up @@ -1587,7 +1591,7 @@ module ProjectViewer =
sources
|> List.choose (
function
| ProjectItem.Compile(name, fullPath) -> Some(name, fullPath)
| ProjectItem.Compile(name, fullPath, _) -> Some(name, fullPath)
)
|> List.filter (fun (_, p) -> includeSourceFile p)

Expand Down
29 changes: 28 additions & 1 deletion src/Ionide.ProjInfo/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Types =
| Exe
| Custom of string

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

type ProjectOptions = {
ProjectId: string option
Expand All @@ -75,10 +75,37 @@ module Types =
member x.ResolvedTargetPath =
defaultArg x.TargetRefPath x.TargetPath

/// Represents a `<Compile>` node within an fsproj file.
type CompileItem = {
/// The `Compile` node's Include contents, after MSBuild has finished evaluation.
/// For example:
/// * `<Compile Include="Foo.fs"/>` would have this set to "Foo.fs";
/// * `<Compile Include="Bar/Baz.fs"/>` would have `"Bar/Baz.fs"`;
/// * (contrived): `<Compile Include="$(IsPackable).fs"/>` might have `true.fs` or `false.fs`, for example.
Name: string
/// Full path on disk to the F# file this `Compile` node is telling MsBuild to compile.
FullPath: string
/// Value of the `<Link />` sub-node, if one exists.
/// For example, `<Compile Include="Foo.fs"><Link>../bar.fs</Link></Compile` would set this to
/// "../bar.fs" (no further path resolution takes place).
Link: string option
/// All the other metadata in the project file associated with this Compile node.
/// This is a map of "name of metadata key" to "contents of that key".
/// Recall that according to MsBuild, those contents are not actually unrestricted XML, although they sure do look like it!
/// 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
/// project at all.
///
/// For example:
/// * `<Compile Include="Foo.fs"><Something>hello</Something></Compile>` sets the metadata key "Something" to the value "hello".
/// * `<Compile Include="Foo.fs"><Blah Baz="hi" /></Compile>` fails at project load time.
/// * `<Compile Include="Foo.fs"><Blah></Blah></Compile>` sets the metadata key "Blah" to the empty string.
/// * `<Compile Include="Foo.fs"><Blah><Quux></Quux></Blah></Compile>` sets the metadata key "Blah" to the string "<Quux></Quux>".
///
/// This map includes the `Link` value, if it exists, which was also extracted for convenience into the `Link` field
/// of this CompileItem.
///
/// If you specify the same metadata key multiple times, the last value wins. (This is MsBuild's decision, not ours.)
Metadata: Map<string, string>
}

type ToolsPath = ToolsPath of string
Expand Down
4 changes: 2 additions & 2 deletions src/Ionide.ProjInfo/VisualTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ module VisualTree =
projPath
|> getVisualPath None (Some sourceFile) sourceFile

ProjectItem.Compile(name, fullpath)
ProjectItem.Compile(name, fullpath, None)
| Some p ->

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

ProjectItem.Compile(name, fullpath)
ProjectItem.Compile(name, fullpath, Some p.Metadata)

0 comments on commit f789e71

Please sign in to comment.