mhinz / neovim-remote

:ok_hand: Support for --remote and friends.
MIT License
1.73k stars 83 forks source link

neovim-remote trims whitespace from lines in stdin #167

Closed gbrlsnchs closed 2 years ago

gbrlsnchs commented 3 years ago

A little context before the real issue:

I use neovim-remote to open git diffs from inside Neovim's terminal. Outside of it, I simply use Neovim directly, since it's faster. I do that by configuring the env variable GIT_PAGER. Here is how they're configured in a ZSH session depending on whether I'm inside Neovim's terminal:

if [[ -z "${NVIM_LISTEN_ADDRESS}" ]]; then
  export GIT_PAGER="nvim +'Man! | setfiletype git'"
else
  export GIT_PAGER="nvr -cc tabnew --remote-wait +'Man! | setlocal bufhidden=wipe | setfiletype git' -"
fi

The issue

When opening the diff directly with Neovim, it is properly highlighted. On the other hand, when opening with neovim-remote, the hunks are not highlighted. Here are both files and their diff:

Correct diff ``` commit a674c60947349f03d1f56a803c9a3c95d437ec07 (HEAD -> gbrlsnchs-put-debug-logging-api, origin/eduardocfalcao-debug-logging-api-get-endpoint) Author: Luis Eduardo Falcao Date: Thu Jul 15 21:08:24 2021 -0300 Fixing debug flags list endpoint. diff --git a/src/connect/api/debuglog/list.go b/src/connect/api/debuglog/list.go index ea0ad69a12..8a3508fd02 100644 --- a/src/connect/api/debuglog/list.go +++ b/src/connect/api/debuglog/list.go @@ -51,7 +51,7 @@ func (e *listDebugFlagsEndpoint) Handle() api.ApiResult { func getDebugFlags() []debugFlagDTO { regions := debug.GetRegions() - list := make([]debugFlagDTO, len(regions)) + var list []debugFlagDTO for _, region := range regions { list = append(list, debugFlagDTO{ diff --git a/src/connect/api/debuglog/list_test.go b/src/connect/api/debuglog/list_test.go index c68ff88bcd..4ad6be8aab 100644 --- a/src/connect/api/debuglog/list_test.go +++ b/src/connect/api/debuglog/list_test.go @@ -78,13 +78,14 @@ func (s *ListEndpointSuite) TestHandle(c *check.C) { apiResult := endpoint.Handle() - c.Check(apiResult.Response, check.Equals, http.StatusOK) - c.Check(apiResult.Err, check.IsNil) - apiContentResult := apiResult.Json.([]debugFlagDTO) debugFlagMap := debugFlagListToMap(apiContentResult) - regionNames := debug.GetRegionNames() + + c.Check(apiResult.Response, check.Equals, http.StatusOK) + c.Check(apiResult.Err, check.IsNil) + c.Check(len(apiContentResult), check.Equals, len(regionNames)) + for _, regionName := range regionNames { if enabled, ok := debugFlagMap[regionName]; ok { c.Check(enabled, check.Equals, debug.Enabled(debug.GetRegion(regionName))) ```
Ill-generated diff ``` commit a674c60947349f03d1f56a803c9a3c95d437ec07 (HEAD -> gbrlsnchs-put-debug-logging-api, origin/eduardocfalcao-debug-logging-api-get-endpoint) Author: Luis Eduardo Falcao Date: Thu Jul 15 21:08:24 2021 -0300 Fixing debug flags list endpoint. diff --git a/src/connect/api/debuglog/list.go b/src/connect/api/debuglog/list.go index ea0ad69a12..8a3508fd02 100644 --- a/src/connect/api/debuglog/list.go +++ b/src/connect/api/debuglog/list.go @@ -51,7 +51,7 @@ func (e *listDebugFlagsEndpoint) Handle() api.ApiResult { func getDebugFlags() []debugFlagDTO { regions := debug.GetRegions() - list := make([]debugFlagDTO, len(regions)) + var list []debugFlagDTO for _, region := range regions { list = append(list, debugFlagDTO{ diff --git a/src/connect/api/debuglog/list_test.go b/src/connect/api/debuglog/list_test.go index c68ff88bcd..4ad6be8aab 100644 --- a/src/connect/api/debuglog/list_test.go +++ b/src/connect/api/debuglog/list_test.go @@ -78,13 +78,14 @@ func (s *ListEndpointSuite) TestHandle(c *check.C) { apiResult := endpoint.Handle() - c.Check(apiResult.Response, check.Equals, http.StatusOK) - c.Check(apiResult.Err, check.IsNil) - apiContentResult := apiResult.Json.([]debugFlagDTO) debugFlagMap := debugFlagListToMap(apiContentResult) - regionNames := debug.GetRegionNames() + + c.Check(apiResult.Response, check.Equals, http.StatusOK) + c.Check(apiResult.Err, check.IsNil) + c.Check(len(apiContentResult), check.Equals, len(regionNames)) + for _, regionName := range regionNames { if enabled, ok := debugFlagMap[regionName]; ok { c.Check(enabled, check.Equals, debug.Enabled(debug.GetRegion(regionName))) ```

And here is the diff between both output diffs:

12c12
<  
---
> 
17c17
<  
---
> 
25c25
<  
---
> 
27c27
<  
---
> 

That said, the issue seems to be in lines where there's only a whitespace. neovim-remote manages to trim them somehow, messing with the highlighting (the whitespaces are needed in order to highlight hunks properly).

gbrlsnchs commented 3 years ago

The following seems to be the culprit, and I have no idea why it exists, since it modifies the original input. https://github.com/mhinz/neovim-remote/blob/1ec7c6c76a66d8d381f54570d6fdd3079c190ba5/nvr/nvr.py#L92

mhinz commented 2 years ago

Fixed by your https://github.com/mhinz/neovim-remote/commit/1aa1651c335bf368422f36d6717f2a57b90d4d99 ;]