Skip to content

Commit

Permalink
Set current solution directory as workspace root uri (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Gołębiowski <[email protected]>
Co-authored-by: Beatrix <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 7d8a10e commit fb016a5
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 41 deletions.
13 changes: 6 additions & 7 deletions src/Cody.Core/Agent/IAgentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,25 @@ public interface IAgentService
void Initialized();

[AgentMethod("git/codebaseName")]
Task<string> GetGitCodebaseName(string url);
Task<string> GetGitCodebaseName(CodyFilePath path);

[AgentMethod("webview/resolveWebviewView")]
Task ResolveWebviewView(ResolveWebviewViewParams paramValue);

[AgentMethod("webview/receiveMessageStringEncoded")]
Task ReceiveMessageStringEncoded(ReceiveMessageStringEncodedParams paramValue);

[AgentMethod("env/openExternal")]
Task OpenExternal(string url);

[AgentMethod("textDocument/didOpen")]
void DidOpen(ProtocolTextDocument docState);

[AgentMethod("textDocument/didChange")]
void DidChange(ProtocolTextDocument docState);

[AgentMethod("textDocument/didFocus")]
void DidFocus(string uri);
void DidFocus(CodyFilePath path);

[AgentMethod("textDocument/didSave")]
void DidSave(string uri);
void DidSave(CodyFilePath path);

[AgentMethod("textDocument/didClose")]
void DidClose(ProtocolTextDocument docState);
Expand All @@ -49,6 +46,8 @@ public interface IAgentService

[AgentMethod("chat/web/new")]
Task<ChatPanelInfo> NewEditorChat();

[AgentMethod("workspaceFolder/didChange")]
Task WorkspaceFolderDidChange(CodyFilePath path);
}
}

18 changes: 7 additions & 11 deletions src/Cody.Core/Agent/InitializeCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Cody.Core.Infrastructure;
using Cody.Core.Logging;
using Cody.Core.Settings;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Cody.Core.Agent
Expand All @@ -16,42 +14,41 @@ public class InitializeCallback
private readonly IVersionService versionService;
private readonly IVsVersionService vsVersionService;
private readonly IStatusbarService statusbarService;
private readonly ISolutionService solutionService;
private readonly ILog log;

public InitializeCallback(
IUserSettingsService userSettingsService,
IVersionService versionService,
IVsVersionService vsVersionService,
IStatusbarService statusbarService,
ISolutionService solutionService,
ILog log)
{
this.userSettingsService = userSettingsService;
this.versionService = versionService;
this.vsVersionService = vsVersionService;
this.statusbarService = statusbarService;
this.solutionService = solutionService;
this.log = log;
}

public async Task Initialize(IAgentService client)
{
// TODO: Get the solution directory path that the user is working on.
var solutionDirPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var wf = Path.Combine(solutionDirPath, "source", "repos");

var clientInfo = new ClientInfo
{
Name = "VisualStudio",
Version = versionService.Full,
IdeVersion = vsVersionService.Version.ToString(),
WorkspaceRootUri = new Uri(wf).ToString(),
WorkspaceRootUri = solutionService.GetSolutionDirectory(),
Capabilities = new ClientCapabilities
{
Edit = Capability.Enabled,
EditWorkspace = Capability.Enabled,
Edit = Capability.None,
EditWorkspace = Capability.None,
CodeLenses = Capability.None,
ShowDocument = Capability.Enabled,
Ignore = Capability.Enabled,
UntitledDocuments = Capability.Enabled,
UntitledDocuments = Capability.None,
Webview = "native",
WebviewNativeConfig = new WebviewCapabilities
{
Expand All @@ -69,7 +66,6 @@ public async Task Initialize(IAgentService client)
AutocompleteAdvancedProvider = null,
Debug = true,
VerboseDebug = true,
// Codebase = "github.com/sourcegraph/cody",

}
};
Expand Down
38 changes: 38 additions & 0 deletions src/Cody.Core/Agent/NotificationHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EnvDTE80;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

Expand Down Expand Up @@ -176,6 +177,43 @@ public void ExtensionConfigDidChange(ExtensionConfiguration config)
DebugLog(config.ToString(), "didChange");
}

[AgentNotification("ignore/didChange")]
public void IgnoreDidChange()
{
DebugLog("Changed", "IgnoreDidChange");
}

// REQUEST FROM AGENT
[AgentNotification("textDocument/show")]
public Task<bool> ShowTextDocument(TextDocumentShowParams param)
{
DebugLog(param.Uri, "ShowTextDocument");
OpenAgentTextDocument(new Uri(param.Uri).ToString());
return Task.FromResult(true);
}

[AgentNotification("env/openExternal")]
public Task<bool> OpenExternalLink(CodyFilePath path)
{
DebugLog(path.Uri, "OpenExternalLink");
if (Uri.TryCreate(path.Uri, UriKind.RelativeOrAbsolute, out var uri))
{
if (uri.IsFile)
{
OpenAgentTextDocument(uri.LocalPath); // Use LocalPath for files
}
}
// Open the URL in the default browser
System.Diagnostics.Process.Start(path.Uri);
return Task.FromResult(true);
}

private void OpenAgentTextDocument(string uri)
{
var dte = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE");
dte.ItemOperations.OpenFile(uri);
}

public void DebugLog(string message, string origin)
{
// Log the message to the debug console when in debug mode.
Expand Down
7 changes: 7 additions & 0 deletions src/Cody.Core/Agent/Protocol/CodyFilePath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Cody.Core.Agent.Protocol
{
public class CodyFilePath
{
public string Uri { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.Core.Agent.Protocol
namespace Cody.Core.Agent.Protocol
{
public class ReceiveMessageStringEncodedParams
{
Expand Down
9 changes: 9 additions & 0 deletions src/Cody.Core/Agent/Protocol/TextDocumentShowParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Cody.Core.Agent.Protocol
{
public class TextDocumentShowParams
{
public string Uri { get; set; }

public TextDocumentShowParamsOptions Options { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/Cody.Core/Agent/Protocol/TextDocumentShowParamsOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.Core.Agent.Protocol
{
public class TextDocumentShowParamsOptions
{
public bool PreserveFocus { get; set; }
public bool Preview { get; set; }
public Range Selection { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Cody.Core/Cody.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<Compile Include="Agent\NotificationHandlers.cs" />
<Compile Include="Agent\Protocol\AuthStatus.cs" />
<Compile Include="Agent\Protocol\ChatPanelInfo.cs" />
<Compile Include="Agent\Protocol\TextDocumentShowParamsOptions.cs" />
<Compile Include="Agent\Protocol\TextDocumentShowParams.cs" />
<Compile Include="Agent\Protocol\CodyFilePath.cs" />
<Compile Include="Agent\Protocol\ClientCapabilities.cs" />
<Compile Include="Agent\Protocol\ClientInfo.cs" />
<Compile Include="Agent\Protocol\ConfigOverwrites.cs" />
Expand All @@ -83,6 +86,7 @@
<Compile Include="DocumentSync\IDocumentSyncActions.cs" />
<Compile Include="Ide\IVsVersionService.cs" />
<Compile Include="Infrastructure\IColorThemeService.cs" />
<Compile Include="Infrastructure\ISolutionService.cs" />
<Compile Include="Infrastructure\IStatusbarService.cs" />
<Compile Include="Infrastructure\VersionService.cs" />
<Compile Include="Infrastructure\IVersionService.cs" />
Expand Down
6 changes: 2 additions & 4 deletions src/Cody.Core/DocumentSync/DocumentSyncCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Cody.Core.DocumentSync
{
Expand Down Expand Up @@ -104,7 +102,7 @@ public void OnClosed(string fullPath)
public void OnFocus(string fullPath)
{
logger.Debug($"Sending DidFocus() for '{fullPath}'");
agentService.DidFocus(ToUri(fullPath));
agentService.DidFocus(new CodyFilePath { Uri = ToUri(fullPath) });

}

Expand Down Expand Up @@ -157,7 +155,7 @@ public void OnSaved(string fullPath)
{
logger.Debug($"Sending DidSave() for '{fullPath}'");

agentService.DidSave(ToUri(fullPath));
agentService.DidSave(new CodyFilePath { Uri = ToUri(fullPath) });
}
}
}
15 changes: 15 additions & 0 deletions src/Cody.Core/Infrastructure/ISolutionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.Core.Infrastructure
{
public interface ISolutionService
{
bool IsSolutionOpen();

string GetSolutionDirectory();
}
}
2 changes: 1 addition & 1 deletion src/Cody.UI/Controls/WebView2Dev.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ public ICommand SendMessage
set => SetValue(SendMessageProperty, value);
}
}
}
}
1 change: 0 additions & 1 deletion src/Cody.VisualStudio/Client/AgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,4 @@ private void DisconnectInternal()
log.Info("The connection with the agent has been terminated.");
}
}

}
4 changes: 0 additions & 4 deletions src/Cody.VisualStudio/Client/IAgentConnector.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.VisualStudio.Client
{
Expand Down
1 change: 1 addition & 0 deletions src/Cody.VisualStudio/Cody.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="Services\OptionsPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Services\SolutionService.cs" />
<Compile Include="Services\ThemeService.cs" />
<Compile Include="Services\StatusbarService.cs" />
<Compile Include="Services\UserSettingsProvider.cs" />
Expand Down
Loading

0 comments on commit fb016a5

Please sign in to comment.