This repository was archived by the owner on Mar 17, 2025. It is now read-only.
Repository navigation
Add go to definition for packages #27
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net.Http; | ||
| using EnvDTE; | ||
| using FarTestProvider; | ||
| using Microsoft.VisualStudio; | ||
|
|
@@ -10,7 +11,9 @@ | |
| using Microsoft.VisualStudio.Text; | ||
| using Microsoft.VisualStudio.Text.Editor; | ||
| using Microsoft.VisualStudio.TextManager.Interop; | ||
| using ProjectFileTools.Completion; | ||
| using ProjectFileTools.MSBuild; | ||
| using ProjectFileTools.NuGetSearch.Contracts; | ||
|
|
||
| namespace ProjectFileTools | ||
| { | ||
|
|
@@ -41,11 +44,55 @@ public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, Int | |
| return Next?.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText) ?? (int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED; | ||
| } | ||
|
|
||
| private static bool PackageExistsOnNuGet(string packageName, string version, out string url) | ||
| { | ||
| string packageAndVersionUrl = $"https://www.nuget.org/packages/{packageName}/{version}/"; | ||
| string packageUrl = $"https://www.nuget.org/packages/{packageName}/"; | ||
|
|
||
| try | ||
| { | ||
| using (HttpClient client = new HttpClient()) | ||
| { | ||
| HttpResponseMessage response = client.GetAsync(packageAndVersionUrl).Result; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to issue a HEAD request here? You're not interested in the body after all... |
||
|
|
||
| if (response.StatusCode == System.Net.HttpStatusCode.OK) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of a NuGet gallery bug (NuGet/NuGetGallery#4624), this will always be true, as long as the package ID is correct. |
||
| { | ||
| url = packageAndVersionUrl; | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| response = client.GetAsync(packageAndVersionUrl).Result; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you fetching the same URL again? Isn't this supposed to be |
||
|
|
||
| if (response.StatusCode == System.Net.HttpStatusCode.OK) | ||
| { | ||
| url = packageUrl; | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| catch { } | ||
|
|
||
| url = null; | ||
| return false; | ||
| } | ||
|
|
||
| public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) | ||
| { | ||
| if (pguidCmdGroup == _vSStd97CmdIDGuid && nCmdID == (uint)VSConstants.VSStd97CmdID.GotoDefn) | ||
| { | ||
| TextView.TextBuffer.Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out ITextDocument textDoc); | ||
|
|
||
| if (PackageCompletionSource.IsInRangeForPackageCompletion(TextView.TextSnapshot, TextView.Caret.Position.BufferPosition.Position, out Span targetSpan, out string packageName, out string packageVersion, out string completionType)) | ||
| { | ||
| if(PackageExistsOnNuGet(packageName, packageVersion, out string url)) | ||
| { | ||
| System.Diagnostics.Process.Start(url); | ||
| return VSConstants.S_OK; | ||
| } | ||
| } | ||
|
|
||
| IWorkspace workspace = _workspaceManager.GetWorkspace(textDoc.FilePath); | ||
| List<Definition> definitions = workspace.ResolveDefinition(textDoc.FilePath, TextView.TextSnapshot.GetText(), TextView.Caret.Position.BufferPosition.Position); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if the logic of finding the Nuget package would reside inside the .Nuget project.
On a side note, the Definition class is intended to be an abstraction level for the set of matches. However, the implementation currently is very limited (we would need to implement what we were calling Resolvers; that would allow us to write this code in a more generic way).
For now, I think that is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #29 to track moving the logic