ReSharper 2021.3.1 - Copy Code Reference Placeholders & Wrong Image in Blog Post

Hey ReSharper Team, I've already posted this here https://blog.jetbrains.com/dotnet/2021/12/10/rider-2021-3-1-and-resharper-2021-3-1/#remark42.

I think that was not the right place so I will try my luck here instead. No need to answer/read my original comment, I will include all details here.

---

Thank you very much for the update and the new features.
I’ve just updated and read https://www.jetbrains.com/resharper/whatsnew/.

I want to use the «Copy Code Reference» feature with a custom template URL, but it fails.

The example/doc seems wrong. The example doesn’t even work. It displays:
Example URI: https://org.jetbrains.space/p/net/repositories/files/$GIT_BRANCH$/$GIT_PATH$?line=$LINE$

I think the placeholders are wrong?

I’ve tried adding this with the dialog but afterwards it doesn’t show up in the menu when using «Copy Code Reference».
However, it does work with other placeholders.

https://org.jetbrains.space/p/net/repositories/files/SOMETHING/$PATH_GIT$?line=$LINE$

So the issue here was $GIT_PATH$ (seen in the dialog) which only resolves when using $PATH_GIT$ (like the other one, $PATH_SLN$).
Sadly, I didn’t manage to resolve $GIT_BRANCH$ or $BRANCH_GIT$ so currently I just use «develop».

Could you please check that out and maybe fix the issue or write me the correct placeholder for $GIT_BRANCH$ to use?
Probably best to check all placeholders work, too :)

Additionally: There seems to be a wrong image used for the zoomed in version of the second image in the «Copy Code Reference» section - and many other images. Instead it shows the options when installing/updating ReSharper.
See: https://www.jetbrains.com/resharper/whatsnew/#:~:text=the%20LanguageInjection%20attribute.–,Copy%20Code%20Reference,-This%20release%20brings

7 comments
Comment actions Permalink

Hello Countryen,

thank you for your feedback.

The `GIT_*` templates can be expanded only when `git.exe` is available in PATH. After your question I found out, that nowadays Visual Studio ship `git.exe` with the version control extensions, so I guess it is possible to use this executable to expand templates, I've created issue to check if it is possible. https://youtrack.jetbrains.com/issue/RSRP-488050

Currently, as workaround, you can add directory with git.exe to PATH manually.

0
Comment actions Permalink

Hey Alexander, 

Thank you for your reply.

I will test that again. I should have git.exe in my PATH available (when I write "git" in CMD/PS, we use it all the time).

Also, the issue is not that it doesn't work (it does) but the documentation on the GUI wizzard for the setting does say to use $GIT_PATH$ which doesn't work, BUT $PATH_GIT$, which does indeed work (why is that?).

So do both exist and we should use $GIT_PATH$ instead of $PATH_GIT$?

My problem is that $GIT_BRANCH$ and $BRANCH_GIT$ do not work, but as said, I will test that with the git.exe. Is there a log output or anything I can see the error message to track the issue?

Additionally, if I use the $GIT_PATH$, the command just isn't in my "Copy Code Reference" menu anymore (it's missing). However, if I use just $GIT_BRANCH$ the command is there with "GIT_BRANCH" in the URL.

---

The zoom in version of the images I referenced is still wrong - should I make another post for this issue?

0
Comment actions Permalink

I've just found this where you can see the issue.

https://blog.jetbrains.com/dotnet/2021/10/11/copy-code-reference-in-resharper-and-rider-2021-3-eap/

In the first image under "Adding Custom URI Patterns" you can see the configured values, including:

BitBucket $BRANCH$ = https://bitbucket.org/company/project/src/$BRANCH$/$PATH_GIT$#lines-$  (... image ends here)

But, underneath it lists the macros, including the "wrong" versions:

$GIT_PATH$        Git: Path to file relative to the Git root
$GIT_BRANCH$  Git: Branch

Shouldn't this be "PATH_GIT" and "BRANCH" then? I will try using $BRANCH$ next time, too.

0
Comment actions Permalink

Hey Countryen,

sorry for the delayed reply.

There are hidden patterns for backward-compatibility. Some patterns were renamed, but I preserved old names for customers who already defined URL-patterns.
PATH_GIT was intended to be hidden alias for GIT_PATH, but I made a mistake and it became alias for PATH_SLN
I checked, that others aliases are defined correctly, so BRANCH is the same as GIT_BRANCH. There is no need to use hidden alias here and I suggest using GIT_BRANCH.

The definition of GIT_PATH macro isn't wrong. I guess something is wrong with either repository or git installation.
We use `git rev-parse --abbrev-ref HEAD` for `$GIT_BRANCH` macro, could you check this command it in cmd.exe in your project directory?

there a log output or anything I can see the error message to track the issue?

Of course! You can open current log file by using Extensions -> ReSharper -> Help -> Show Log command.
Search for `Running git command` phrase (it is logged by GitCommandRunner)

The zoom in version of the images I referenced is still wrong - should I make another post for this issue?

No, I reported it to the responsible team as soon as reported it. This issue should be fixed now. Thanks again for letting us know!

Additionally, if I use the $GIT_PATH$, the command just isn't in my "Copy Code Reference" menu anymore (it's missing)

I agree that this is confusing behavior. I've slightly improved UX here in the upcoming 2022.2 release. The errors from git invocation will be displayed in the menu items instead of silently hiding them.

1
Comment actions Permalink

Hey Alexander,

Thank you for the detailed information, that helps and explains a lot of my confusion :) 

Okay I've checked, I don't have git.exe on my PATH (probably because VS can use its own git.exe nowadays, as you said). Is it possible to tell ReSharper where git.exe is instead of using PATH? I've now put git.exe on my PATH to test this.

The git command you provided works and returns the correct branch name for me in the git root in cmd (now).

 

I've checked the log file (before setting git.exe on the PATH) but it just logs this every time I open the context menu for "Copy Code Reference":

--- EXCEPTION #1/2 [KeyNotFoundException]
Message = “The given key was not present in the dictionary.”
ExceptionPath = Root.InnerException
ClassName = System.Collections.Generic.KeyNotFoundException
Data.ThreadLocalDebugInfo = “
  signal `LocalProtocol.LocalProtocolStub.handshake.$.result` (7048076752749644047)
   -> property `LocalProtocol.LocalProtocolStub.handshake` (2127320895554122)
   -> OleCommandTargetExec
HResult = COR_E_KEYNOTFOUND=80131577

--- EXCEPTION #2/2 [LoggerException]
Message = “The given key was not present in the dictionary.”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
InnerException = “Exception #1 at Root.InnerException”
HResult = COR_E_APPLICATION=80131600

(The gist of it, if you need the full log I can upload a file as it's quite verbose).

There's no mentioning of "Running git command" or "GitCommandRunner". But knowing about the log file at all helps a lot for other cases.

 

After setting git.exe on my PATH and restarting VS it works now - hurray. Maybe you can include that you need git.exe on PATH in the docs / on the GUI page, I doubt I am the only one not having git.exe on PATH.

 

Any chance I can define a macro or transform a macro content? I just need the folder name of the project because that's part of our URL. I have the folder name in PATH_SLN but not just the folder name. Reading a git property would be sufficient, too.

 

> This issue should be fixed now

Great :) I've checked and now the correct images are displayed and you can even see more details than I expected 👍

 

Thank you very much for your support already.

0
Comment actions Permalink

Countryen ,

glad to hear that it helped you!

Maybe you can include that you need git.exe on PATH in the docs / on the GUI page, 

I've already support using git from Visual Studio's installation, so it shouldn't an issue anymore since 2022.2 version. https://youtrack.jetbrains.com/issue/RSRP-488050

Reading a git property would be sufficient, too.

Currently, there are no macros. May I ask you to raise an issue in our bug tracker with detailed scheme of your directory tree. I cannot understand how reading git property may be more helpful than defining a constant in settings.

0
Comment actions Permalink

Hey Alexander,

Great to hear that it's supported in 2022 :) 

I will create the bug tracker issue but here's the explanation for you in short:

  • The name of my folder is the repo name.
  • I have one folder per repo (around 10)
  • The URL is somethling like "http://www.vcs.com/repos/<repo name>/..." so I could insert the folder name as <repo name>.
0

Please sign in to leave a comment.