Skip to content

Commit

Permalink
Autocomplete compatibility fix part 2 (#199)
Browse files Browse the repository at this point in the history
Autocomplete loads and initialize via MEF independently from the main extension. It allows to avoid extension crashes in Visual Studio versions below 17.6, which doesn't support using `Microsoft.VisualStudio.Language` library, more precisely
`Microsoft.VisualStudio.Threading` v17.6 (check #198). 

If the current VS version supports `Microsoft.VisualStudio.Language`, `Cody.VisualStudio.Completions.dll` will be silently loaded via MEF. Otherwise, `Cody.VisualStudio.Completions.dll` won't be loaded, but the main extension will be working.

In the future, if Visual Studio will introduce breaking changes to Microsoft.VisualStudio.Language API, the main extension with chat will still be working, but autocomplete will be silently turned off.

It was tested against VS versions:

17.7.6
17.9 Preview 2
17.10.3
17.12
17.13.0 Preview 2.1
  • Loading branch information
PiotrKarczmarz authored Jan 21, 2025
1 parent d0f2fc0 commit 10b0860
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ jobs:
shell: pwsh
run: ./agent/runBuildAgent.ps1


- name: Build extension (${{ env.Configuration }})
run: msbuild src/Cody.sln -t:Build -restore -verbosity:minimal -property:Configuration=${{ env.Configuration }}
shell: pwsh
run: ./src/build.ps1 -configuration ${{ env.Configuration }}

- name: Upload Cody.VisualStudio.vsix artifact
uses: actions/upload-artifact@v4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ jobs:
run: ./agent/buildAgent.ps1 -version ${{ steps.cody.outputs.tag }}

- name: Build extension (${{ env.Configuration }})
run: msbuild src/Cody.sln -t:Build -restore -verbosity:minimal -property:Configuration=${{ env.Configuration }}
shell: pwsh
run: ./src/build.ps1 -configuration ${{ env.Configuration }}

- name: Upload Cody.VisualStudio.vsix artifact
uses: actions/upload-artifact@v4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ jobs:
vsix-manifest-file: src\Cody.VisualStudio\source.extension.vsixmanifest

- name: Build extension (${{ env.Configuration }})
run: msbuild src/Cody.sln -t:Build -restore -verbosity:minimal -property:Configuration=${{ env.Configuration }}
shell: pwsh
run: ./src/build.ps1 -configuration ${{ env.Configuration }}

- name: Upload Cody.VisualStudio.vsix artifact
uses: actions/upload-artifact@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cody.VisualStudio.Completions</RootNamespace>
<AssemblyName>Cody.VisualStudio.Completions</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Completions\CodyProposalCollection.cs" />
<Compile Include="Completions\CodyProposalManager.cs" />
<Compile Include="Completions\CodyProposalManagerProvider.cs" />
<Compile Include="Completions\CodyProposalSource.cs" />
<Compile Include="Completions\CodyProposalSourceProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Language">
<Version>17.6.268</Version>
</PackageReference>
<PackageReference Include="StreamJsonRpc">
<Version>2.15.29</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cody.Core\Cody.Core.csproj">
<Project>{9ff2cc40-78e9-46c8-b2ef-30a1f1be82f2}</Project>
<Name>Cody.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Cody.VisualStudio\Cody.VisualStudio.csproj">
<Project>{3bb34f98-f069-4a38-bc4d-cf407d59b863}</Project>
<Name>Cody.VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions src/Cody.VisualStudio.Completions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cody.VisualStudio.Completions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cody.VisualStudio.Completions")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9c7c76c1-0e9c-4a19-88d3-de00ad1a5521")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
38 changes: 28 additions & 10 deletions src/Cody.VisualStudio/Cody.VisualStudio.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
Expand Down Expand Up @@ -55,11 +55,6 @@
<Compile Include="Client\TraceJsonRpc.cs" />
<Compile Include="CodyPackage.ErrorHandling.cs" />
<Compile Include="CodyToolWindow.cs" />
<Compile Include="Completions\CodyProposalCollection.cs" />
<Compile Include="Completions\CodyProposalManager.cs" />
<Compile Include="Completions\CodyProposalManagerProvider.cs" />
<Compile Include="Completions\CodyProposalSource.cs" />
<Compile Include="Completions\CodyProposalSourceProvider.cs" />
<Compile Include="Infrastructure\LoggerFactory.cs" />
<Compile Include="Infrastructure\WindowPaneLogger.cs" />
<Compile Include="Infrastructure\VsConstants.cs" />
Expand Down Expand Up @@ -124,9 +119,6 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Language">
<Version>17.6.268</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.0-previews-4-31709-430" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.6.2164">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -139,6 +131,32 @@
</VSCTCompile>
<Content Include="Resources\CodyToolWindowCommand.png" />
</ItemGroup>

<!--Completions dll start -->

<!--Workaround to get Cody.VisualStudio.Completions compiled when using Visual Studio to run and debug the extension
Only works with Visual Studio, but unfortunately not with msbuild-->
<Target Name="Completions" BeforeTargets="GetVsixSourceItems"
Condition="'$(BuildingInsideVisualStudio)' == 'true'"
>
<MSBuild Projects="..\Cody.VisualStudio.Completions\Cody.VisualStudio.Completions.csproj"
Properties="Configuration=$(Configuration)"
Targets="Build" />
</Target>

<Target Name="CopyCompletionsDllToVsix" BeforeTargets="GetVsixSourceItems">
<PropertyGroup>
<CompletionsDllPath>..\Cody.VisualStudio.Completions\bin\$(Configuration)\Cody.VisualStudio.Completions.dll</CompletionsDllPath>
</PropertyGroup>

<ItemGroup Condition="Exists('$(CompletionsDllPath)')">
<VSIXSourceItem Include="$(CompletionsDllPath)">
<VSIXSubPath>.</VSIXSubPath>
</VSIXSourceItem>
</ItemGroup>
</Target>
<!--Completions dll end -->

<ItemGroup>
<ProjectReference Include="..\Cody.Core\Cody.Core.csproj">
<Project>{9FF2CC40-78E9-46C8-B2EF-30A1F1BE82F2}</Project>
Expand All @@ -159,4 +177,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/Cody.VisualStudio/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="Cody.VisualStudio.Completions.dll" />
</Assets>
</PackageManifest>
10 changes: 10 additions & 0 deletions src/Cody.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cody.Core.Tests", "Cody.Core.Tests\Cody.Core.Tests.csproj", "{9B46B477-E57A-4F19-A240-56D5D3C7EE8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cody.VisualStudio.Completions", "Cody.VisualStudio.Completions\Cody.VisualStudio.Completions.csproj", "{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -94,6 +96,14 @@ Global
{9B46B477-E57A-4F19-A240-56D5D3C7EE8F}.Release|Any CPU.Build.0 = Release|Any CPU
{9B46B477-E57A-4F19-A240-56D5D3C7EE8F}.Release|x86.ActiveCfg = Release|Any CPU
{9B46B477-E57A-4F19-A240-56D5D3C7EE8F}.Release|x86.Build.0 = Release|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Debug|x86.ActiveCfg = Debug|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Debug|x86.Build.0 = Debug|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Release|Any CPU.Build.0 = Release|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Release|x86.ActiveCfg = Release|Any CPU
{9C7C76C1-0E9C-4A19-88D3-DE00AD1A5521}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 10 additions & 0 deletions src/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
param(
$configuration = "Debug"
)

$current = $PSScriptRoot
Write-Output "Building using $configuration configuration ..."

& msbuild $current/Cody.VisualStudio.Completions/Cody.VisualStudio.Completions.csproj -t:Build -restore -verbosity:minimal -property:Configuration=$configuration

& msbuild $current/Cody.sln -t:Build -restore -verbosity:minimal -property:Configuration=$configuration

0 comments on commit 10b0860

Please sign in to comment.