feat: detect sln and sln files as project files

This commit is contained in:
Paulo Morgado 2023-10-22 12:43:47 +01:00 committed by Jan De Dobbeleer
parent ca27d2ab0c
commit 1b20c82440
3 changed files with 10 additions and 5 deletions

View file

@ -39,6 +39,7 @@ require (
github.com/mattn/go-runewidth v0.0.15 github.com/mattn/go-runewidth v0.0.15
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/mod v0.13.0 golang.org/x/mod v0.13.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
@ -89,7 +90,6 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect github.com/shopspring/decimal v1.3.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sync v0.4.0 // indirect golang.org/x/sync v0.4.0 // indirect
golang.org/x/term v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/regex" "github.com/jandedobbeleer/oh-my-posh/src/regex"
"golang.org/x/exp/slices"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
) )
@ -110,7 +111,7 @@ func (n *Project) Init(props properties.Properties, env platform.Environment) {
}, },
{ {
Name: "dotnet", Name: "dotnet",
Files: []string{"*.vbproj", "*.fsproj", "*.csproj"}, Files: []string{"*.sln", "*.slnf", "*.vbproj", "*.fsproj", "*.csproj"},
Fetcher: n.getDotnetProject, Fetcher: n.getDotnetProject,
}, },
{ {
@ -205,18 +206,22 @@ func (n *Project) getNuSpecPackage(_ ProjectItem) *ProjectData {
} }
func (n *Project) getDotnetProject(_ ProjectItem) *ProjectData { func (n *Project) getDotnetProject(_ ProjectItem) *ProjectData {
files := n.env.LsDir(n.env.Pwd())
var name string var name string
var content string var content string
extensions := []string{".sln", ".slnf", ".csproj", ".fsproj", ".vbproj"}
files := n.env.LsDir(n.env.Pwd())
// get the first match only // get the first match only
for _, file := range files { for _, file := range files {
extension := filepath.Ext(file.Name()) extension := filepath.Ext(file.Name())
if extension == ".csproj" || extension == ".fsproj" || extension == ".vbproj" { if slices.Contains(extensions, extension) {
name = strings.TrimSuffix(file.Name(), filepath.Ext(file.Name())) name = strings.TrimSuffix(file.Name(), filepath.Ext(file.Name()))
content = n.env.FileContent(file.Name()) content = n.env.FileContent(file.Name())
break break
} }
} }
// the name of the parameter may differ depending on the version, // the name of the parameter may differ depending on the version,
// so instead of xml.Unmarshal() we use regex: // so instead of xml.Unmarshal() we use regex:
tag := "(?P<TAG><.*TargetFramework.*>(?P<TFM>.*)</.*TargetFramework.*>)" tag := "(?P<TAG><.*TargetFramework.*>(?P<TFM>.*)</.*TargetFramework.*>)"

View file

@ -15,7 +15,7 @@ Supports:
- Poetry project (`pyproject.toml`) - Poetry project (`pyproject.toml`)
- PHP project (`composer.json`) - PHP project (`composer.json`)
- Any nuspec based project (`*.nuspec`, first file match info is displayed) - Any nuspec based project (`*.nuspec`, first file match info is displayed)
- .NET project (`*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed) - .NET project (`*.sln`, `*.slnf`, `*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed)
- Julia project (`JuliaProject.toml`, `Project.toml`) - Julia project (`JuliaProject.toml`, `Project.toml`)
- PowerShell project (`*.psd1`, first file match info is displayed) - PowerShell project (`*.psd1`, first file match info is displayed)