Skip to content

Commit

Permalink
Merge pull request #1 from rpbeukes/fix-incorrect-code-suggestion
Browse files Browse the repository at this point in the history
Fix incorrect code suggestions.

Related to this [issue](MrLuje#14)

Might not be the best fix, but it works for my scenario.
  • Loading branch information
rpbeukes authored Jun 16, 2022
2 parents 5eea011 + 3d89f60 commit 46541b1
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/CI_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI-master

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
name: build
runs-on: windows-latest
steps:
- name: checkout code
uses: actions/checkout@v3

- name: get Version from source.extension.vsixmanifest, and append version with run_number
run: |
$manifestPath = '${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.Vsix\source.extension.vsixmanifest'
$manifestXml = [xml](Get-Content $manifestPath -Raw)
$version = $manifestXml.PackageManifest.Metadata.Identity.Version
$split = $version.Split('.')
$version = $split[0] + '.' + $split[1] + '.' + $split[2] + '.' + ${{ github.run_number }}
echo "APP_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
$manifestXml.PackageManifest.Metadata.Identity.Version = $version
$manifestXml.save($manifestPath)
- name: Print content of source.extension.vsixmanifest
run: get-content .\Mocking.Helpers\Mocking.Helpers.Vsix\source.extension.vsixmanifest

- name: print APP_VERSION
run: Write-Host $APP_VERSION

- name: add msbuild to PATH
uses: microsoft/[email protected]

- name: setup nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: '6.x'

- name: nuget restore
run: nuget restore Mocking.Helpers.sln

- name: build solution
run: msbuild Mocking.Helpers.sln -t:rebuild -property:Configuration=Release

- name: rename Mocking.Helpers.vsix to Mocking.Helpers.W.X.Y.Z.vsix
run: ren ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.vsix\bin\Release\Mocking.Helpers.vsix Mocking.Helpers.${{ env.APP_VERSION }}.vsix

- name: create artifact
uses: actions/upload-artifact@v3
with:
name: Mocking.Helpers.${{ env.APP_VERSION }}.vsix
path: ${{ github.workspace }}\Mocking.Helpers\Mocking.Helpers.vsix\bin\Release\Mocking.Helpers.${{ env.APP_VERSION }}.vsix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<UpgradeBackupLocation />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand All @@ -25,7 +26,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mocking.Helpers.Vsix</RootNamespace>
<AssemblyName>Mocking.Helpers</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[17.0,18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[15.0,17.0)">
<InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[15.0,18.0)">
<ProductArchitecture>x86</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[17.0,18.0)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
{
if (!context.Document.SupportsSemanticModel || !context.Document.SupportsSyntaxTree) return;

var hasFakeItEasyReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName));
var hasFakeItEasyReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase));
if (!hasFakeItEasyReferenced) return;

var syntaxRoot = await context.Document.GetSyntaxRootAsync();
Expand Down
3 changes: 2 additions & 1 deletion Mocking.Helpers/Mocking.Helpers/Moq/MoqIsAnyCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
{
if (!context.Document.SupportsSemanticModel || !context.Document.SupportsSyntaxTree) return;

var hasMoqReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName));
var hasMoqReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase));

if (!hasMoqReferenced) return;

var syntaxRoot = await context.Document.GetSyntaxRootAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
{
if (!context.Document.SupportsSemanticModel || !context.Document.SupportsSyntaxTree) return;

var hasNSubstituteReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName));
var hasNSubstituteReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase));

if (!hasNSubstituteReferenced) return;

var syntaxRoot = await context.Document.GetSyntaxRootAsync();
Expand Down
24 changes: 24 additions & 0 deletions Mocking.Helpers/Mocking.Helpers/PackagesHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;

namespace Mocking.Helpers
{
public static class PackagesHelper
{
public static IEnumerable<string> GetProjectNugetPackages(Project project)
{
var csproj = new XmlDocument();
csproj.Load(project.FilePath);

var nugetPackages = csproj.SelectNodes("//PackageReference[@Include and @Version]")
.OfType<XmlNode>()
.Select(x => x.Attributes["Include"].Value)
.ToList();

return nugetPackages;
}
}
}

0 comments on commit 46541b1

Please sign in to comment.