Skip to content

Commit 30335c6

Browse files
committed
initial commit
1 parent c34bdfe commit 30335c6

34 files changed

+5531
-2
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
4+
dotnet_diagnostic.CS8632.severity = none

CodeiumVS.sln

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34316.72
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeiumVS", "CodeiumVS\CodeiumVS.csproj", "{B37F2AE5-CDEC-45B3-944D-8EF912810A12}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{15173A19-0B59-409B-9E39-D0EC0DBF5F27}"
9+
ProjectSection(SolutionItems) = preProject
10+
.editorconfig = .editorconfig
11+
EndProjectSection
12+
EndProject
13+
Global
14+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15+
Debug|Any CPU = Debug|Any CPU
16+
Debug|arm64 = Debug|arm64
17+
Debug|x86 = Debug|x86
18+
Release|Any CPU = Release|Any CPU
19+
Release|arm64 = Release|arm64
20+
Release|x86 = Release|x86
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|arm64.ActiveCfg = Debug|arm64
26+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|arm64.Build.0 = Debug|arm64
27+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|x86.ActiveCfg = Debug|x86
28+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Debug|x86.Build.0 = Debug|x86
29+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Release|arm64.ActiveCfg = Release|arm64
32+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Release|arm64.Build.0 = Release|arm64
33+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Release|x86.ActiveCfg = Release|x86
34+
{B37F2AE5-CDEC-45B3-944D-8EF912810A12}.Release|x86.Build.0 = Release|x86
35+
EndGlobalSection
36+
GlobalSection(SolutionProperties) = preSolution
37+
HideSolutionNode = FALSE
38+
EndGlobalSection
39+
GlobalSection(ExtensibilityGlobals) = postSolution
40+
SolutionGuid = {3AAF90C6-22AA-4B1E-BB33-BB9CFE9BFD4A}
41+
EndGlobalSection
42+
EndGlobal

CodeiumVS/CodeiumVS.csproj

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
5+
<LangVersion>latest</LangVersion>
6+
<TargetFrameworkProfile />
7+
</PropertyGroup>
8+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
9+
<PropertyGroup>
10+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
11+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
12+
<SchemaVersion>2.0</SchemaVersion>
13+
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ProjectGuid>{B37F2AE5-CDEC-45B3-944D-8EF912810A12}</ProjectGuid>
15+
<OutputType>Library</OutputType>
16+
<AppDesignerFolder>Properties</AppDesignerFolder>
17+
<RootNamespace>CodeiumVS</RootNamespace>
18+
<AssemblyName>Codeium</AssemblyName>
19+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
20+
<GeneratePkgDefFile>true</GeneratePkgDefFile>
21+
<UseCodebase>true</UseCodebase>
22+
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
23+
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
24+
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
25+
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
26+
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
27+
<StartAction>Program</StartAction>
28+
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
29+
<StartArguments>/rootsuffix Exp</StartArguments>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
32+
<DebugSymbols>true</DebugSymbols>
33+
<DebugType>full</DebugType>
34+
<Optimize>false</Optimize>
35+
<OutputPath>bin\Debug\</OutputPath>
36+
<DefineConstants>DEBUG;TRACE</DefineConstants>
37+
<ErrorReport>prompt</ErrorReport>
38+
<WarningLevel>4</WarningLevel>
39+
<LangVersion>preview</LangVersion>
40+
</PropertyGroup>
41+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
42+
<DebugType>pdbonly</DebugType>
43+
<Optimize>true</Optimize>
44+
<OutputPath>bin\Release\</OutputPath>
45+
<DefineConstants>TRACE</DefineConstants>
46+
<ErrorReport>prompt</ErrorReport>
47+
<WarningLevel>4</WarningLevel>
48+
</PropertyGroup>
49+
<ItemGroup>
50+
<Compile Include="LanguageServer\LanguageServerController.cs" />
51+
<Compile Include="LanguageServer\LanguageServer.cs" />
52+
<Compile Include="LanguageServer\Packets.cs" />
53+
<Compile Include="NotificationBar.cs" />
54+
<Compile Include="Properties\Resources.Designer.cs">
55+
<AutoGen>True</AutoGen>
56+
<DesignTime>True</DesignTime>
57+
<DependentUpon>Resources.resx</DependentUpon>
58+
</Compile>
59+
<Compile Include="Proposal\CodeiumProposalManager.cs" />
60+
<Compile Include="Proposal\CodeiumProposalManagerProvider.cs" />
61+
<Compile Include="Proposal\CodeiumProposalSource.cs" />
62+
<Compile Include="Proposal\CodeiumProposalSourceProvider.cs" />
63+
<Compile Include="Proposal\Mapper.cs" />
64+
<Compile Include="Windows\ChatToolWindow.cs" />
65+
<Compile Include="Windows\EnterTokenDialogWindow.cs" />
66+
<Compile Include="Commands.cs" />
67+
<Compile Include="OutputWindow.cs" />
68+
<Compile Include="Properties\AssemblyInfo.cs" />
69+
<Compile Include="SettingsPage.cs">
70+
<SubType>Component</SubType>
71+
</Compile>
72+
<Compile Include="CodeiumVSPackage.cs" />
73+
<Compile Include="source.extension.cs">
74+
<AutoGen>True</AutoGen>
75+
<DesignTime>True</DesignTime>
76+
<DependentUpon>source.extension.vsixmanifest</DependentUpon>
77+
</Compile>
78+
<Compile Include="VSCommandTable.cs">
79+
<AutoGen>True</AutoGen>
80+
<DesignTime>True</DesignTime>
81+
<DependentUpon>VSCommandTable.vsct</DependentUpon>
82+
</Compile>
83+
</ItemGroup>
84+
<ItemGroup>
85+
<None Include="..\.editorconfig">
86+
<Link>.editorconfig</Link>
87+
</None>
88+
<None Include="app.config" />
89+
<None Include="source.extension.vsixmanifest">
90+
<SubType>Designer</SubType>
91+
<Generator>VsixManifestGenerator</Generator>
92+
<LastGenOutput>source.extension.cs</LastGenOutput>
93+
</None>
94+
<None Include="Resources\ChatLoadingPage.html.txt" />
95+
<Content Include="Resources\Icon.png">
96+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
97+
<IncludeInVSIX>true</IncludeInVSIX>
98+
</Content>
99+
</ItemGroup>
100+
<ItemGroup>
101+
<VSCTCompile Include="VSCommandTable.vsct">
102+
<ResourceName>Menus.ctmenu</ResourceName>
103+
<Generator>VsctGenerator</Generator>
104+
<LastGenOutput>VSCommandTable.cs</LastGenOutput>
105+
</VSCTCompile>
106+
</ItemGroup>
107+
<ItemGroup>
108+
<Reference Include="Microsoft.CSharp" />
109+
<Reference Include="PresentationCore" />
110+
<Reference Include="PresentationFramework" />
111+
<Reference Include="System" />
112+
<Reference Include="System.Design" />
113+
<Reference Include="System.ComponentModel.Composition" />
114+
<Reference Include="System.Drawing" />
115+
<Reference Include="System.Net.Http" />
116+
<Reference Include="System.Xaml" />
117+
<Reference Include="System.Xml" />
118+
<Reference Include="WindowsBase" />
119+
</ItemGroup>
120+
<ItemGroup>
121+
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
122+
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" ExcludeAssets="Runtime">
123+
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
124+
</PackageReference>
125+
<PackageReference Include="Microsoft.VisualStudio.Language">
126+
<Version>17.8.222</Version>
127+
</PackageReference>
128+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.8.2365">
129+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
130+
<PrivateAssets>all</PrivateAssets>
131+
</PackageReference>
132+
<PackageReference Include="Microsoft.Web.WebView2">
133+
<Version>1.0.2151.40</Version>
134+
</PackageReference>
135+
<PackageReference Include="protobuf-net">
136+
<Version>3.2.30</Version>
137+
</PackageReference>
138+
<PackageReference Include="WebSocketSharp">
139+
<Version>1.0.3-rc11</Version>
140+
</PackageReference>
141+
</ItemGroup>
142+
<ItemGroup>
143+
<Page Include="Windows\ChatToolWindowControl.xaml">
144+
<Generator>MSBuild:Compile</Generator>
145+
</Page>
146+
<Page Include="Windows\EnterTokenDialogWindowControl.xaml">
147+
<Generator>MSBuild:Compile</Generator>
148+
</Page>
149+
</ItemGroup>
150+
<ItemGroup>
151+
<EmbeddedResource Include="Properties\Resources.resx">
152+
<Generator>ResXFileCodeGenerator</Generator>
153+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
154+
</EmbeddedResource>
155+
</ItemGroup>
156+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
157+
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
158+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
159+
Other similar extension points exist, see Microsoft.Common.targets.
160+
<Target Name="BeforeBuild">
161+
</Target>
162+
<Target Name="AfterBuild">
163+
</Target>
164+
-->
165+
</Project>

CodeiumVS/CodeiumVSPackage.cs

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
global using Community.VisualStudio.Toolkit;
2+
global using Microsoft.VisualStudio.Shell;
3+
global using System;
4+
global using Task = System.Threading.Tasks.Task;
5+
6+
using Microsoft.VisualStudio;
7+
using Microsoft.VisualStudio.ComponentModelHost;
8+
using Microsoft.VisualStudio.Imaging;
9+
using Microsoft.VisualStudio.Shell.Interop;
10+
using Microsoft.VisualStudio.Threading;
11+
using Microsoft.VisualStudio.Utilities;
12+
using System.Collections.Generic;
13+
using System.ComponentModel.Composition;
14+
using System.ComponentModel.Design;
15+
using System.IO;
16+
using System.Runtime.InteropServices;
17+
using System.Threading;
18+
19+
namespace CodeiumVS;
20+
21+
[Guid(PackageGuids.CodeiumVSString)]
22+
//[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
23+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
24+
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
25+
[ProvideMenuResource("Menus.ctmenu", 1)]
26+
[ProvideOptionPage(typeof(SettingsPage), "Codeium", "Codeium", 0, 0, true)]
27+
[ProvideToolWindow(typeof(ChatToolWindow))]
28+
public sealed class CodeiumVSPackage : ToolkitPackage
29+
{
30+
public static CodeiumVSPackage? Instance = null;
31+
private NotificationInfoBar notificationAuth;
32+
private NotificationInfoBar notificationDownloading;
33+
34+
public OutputWindow outputWindow;
35+
public SettingsPage settingsPage;
36+
public LanguageServer langServer;
37+
38+
39+
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
40+
{
41+
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
42+
await this.SatisfyImportsOnceAsync();
43+
44+
Instance = this;
45+
langServer = new LanguageServer();
46+
outputWindow = new OutputWindow();
47+
settingsPage = (SettingsPage)GetDialogPage(typeof(SettingsPage));
48+
49+
notificationAuth = new NotificationInfoBar(ServiceProvider.GlobalProvider);
50+
notificationDownloading = new NotificationInfoBar(ServiceProvider.GlobalProvider);
51+
52+
await this.RegisterCommandsAsync();
53+
await langServer.InitializeAsync();
54+
55+
await LogAsync("Codeium Extension for Visual Studio");
56+
57+
}
58+
59+
protected override void Dispose(bool disposing)
60+
{
61+
langServer.Dispose();
62+
base.Dispose(disposing);
63+
}
64+
public static void EnsurePackageLoaded()
65+
{
66+
if (Instance != null) return;
67+
68+
ThreadHelper.JoinableTaskFactory.Run(EnsurePackageLoadedAsync);
69+
}
70+
public static async Task EnsurePackageLoadedAsync()
71+
{
72+
if (Instance != null) return;
73+
74+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
75+
IVsShell vsShell = (IVsShell)ServiceProvider.GlobalProvider.GetService(typeof(IVsShell)) ?? throw new NullReferenceException();
76+
77+
Guid guidPackage = new(PackageGuids.CodeiumVSString);
78+
if (vsShell.IsPackageLoaded(ref guidPackage, out var _) == VSConstants.S_OK) return;
79+
80+
if (vsShell.LoadPackage(ref guidPackage, out var _) != VSConstants.S_OK)
81+
throw new NullReferenceException();
82+
}
83+
84+
public async Task UpdateSignedInStateAsync()
85+
{
86+
await JoinableTaskFactory.SwitchToMainThreadAsync();
87+
88+
OleMenuCommandService obj = (await GetServiceAsync(typeof(IMenuCommandService))) as OleMenuCommandService;
89+
obj.FindCommand(new CommandID(PackageGuids.CodeiumVS, PackageIds.SignIn)).Visible = !IsSignedIn();
90+
obj.FindCommand(new CommandID(PackageGuids.CodeiumVS, PackageIds.SignOut)).Visible = IsSignedIn();
91+
obj.FindCommand(new CommandID(PackageGuids.CodeiumVS, PackageIds.EnterAuthToken)).Visible = !IsSignedIn();
92+
93+
// notify the user they need to sign in
94+
if (!IsSignedIn())
95+
{
96+
KeyValuePair<string, Action>[] actions = [
97+
new KeyValuePair<string, Action>("Sign in", delegate { _ = langServer.SignInAsync(); }),
98+
new KeyValuePair<string, Action>("Use authentication token", delegate { new EnterTokenDialogWindow().ShowDialog(); }),
99+
];
100+
101+
notificationAuth.Show("[Codeium] To enable Codeium, please sign in to your account", KnownMonikers.AddUser, true, null, actions);
102+
}
103+
else
104+
{
105+
await notificationAuth.CloseAsync();
106+
}
107+
108+
// find the ChatToolWindow and update it
109+
ChatToolWindow chatWindowPane = (await FindWindowPaneAsync(typeof(ChatToolWindow), 0, false, DisposalToken)) as ChatToolWindow;
110+
chatWindowPane?.Reload();
111+
}
112+
113+
public string GetAppDataPath()
114+
{
115+
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
116+
return Path.Combine(appData, ".codeium");
117+
}
118+
119+
public string GetLanguageServerFolder()
120+
{
121+
return Path.Combine(GetAppDataPath(), $"language_server_v{langServer.GetVersion()}");
122+
}
123+
124+
public string GetLanguageServerPath()
125+
{
126+
return Path.Combine(GetLanguageServerFolder(), "language_server_windows_x64.exe");
127+
}
128+
129+
public string GetAPIKeyPath()
130+
{
131+
return Path.Combine(GetLanguageServerFolder(), "codeium_api_key");
132+
}
133+
134+
public bool IsSignedIn() { return langServer.GetKey().Length > 0; }
135+
public bool HasEnterprise() { return settingsPage.EnterpriseMode; }
136+
137+
internal void Log(string v)
138+
{
139+
// fix this ....
140+
ThreadHelper.JoinableTaskFactory.Run(async delegate
141+
{
142+
await LogAsync(v);
143+
});
144+
}
145+
146+
internal async Task LogAsync(string v)
147+
{
148+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
149+
outputWindow.WriteLine(v);
150+
}
151+
}
152+
153+
154+
// https://gist.github.com/madskristensen/4d205244dd92c37c82e7
155+
public static class MefExtensions
156+
{
157+
private static IComponentModel _compositionService;
158+
159+
public static async Task SatisfyImportsOnceAsync(this object o)
160+
{
161+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
162+
_compositionService ??= ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel)) as IComponentModel;
163+
_compositionService?.DefaultCompositionService.SatisfyImportsOnce(o);
164+
}
165+
}

0 commit comments

Comments
 (0)