Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: handle_leading_whitespace seems to delete all whitespace (?) #159

Closed
benlubas opened this issue Jul 7, 2024 · 12 comments
Closed

bug: handle_leading_whitespace seems to delete all whitespace (?) #159

benlubas opened this issue Jul 7, 2024 · 12 comments

Comments

@benlubas
Copy link
Contributor

benlubas commented Jul 7, 2024

with 0 indent at all, it's fine:
image

With 2 space indent on both lines it's fine:
image

But with 0 leading indent on the code block itself, I do not get correct completions when I'm in an if block.
image

@benlubas
Copy link
Contributor Author

benlubas commented Jul 7, 2024

Hmmm. It seems like it works if there aren't any 0-indent blocks, and only fails when there are a mix of 0-indent and n-indent code blocks in the document

it's very inconsistent

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 8, 2024

I assume the code is all there in the otter buffer, so our keeper.sync_raft code works?

Can you vim.print the params of the completion requests before and after we modify the positions here:

-- take care of potential indents
keeper.modify_position(params, main_nr, true, true)
-- send the request to the otter buffer

Maybe we are missing something. If this is not the case it is something harder to spot.

I previously had issues with the other lsp servers like pyright being out of sync, see

-- this has to happen again after the
-- otter buffers got their own lsps
-- to really make sure the clients are
-- attached to their otter buffers
keeper.sync_raft(main_nr)

What was happening there is as follows. Lsp servers don't actually look at the buffer (most of the time, for pyright we even disable it explicitly due to a bug https://github.com/jmbuhr/quarto-nvim-kickstarter/blob/6455ad9123041f11e3294508db8f216223e2ca8a/lua/plugins/lsp.lua#L288-L296) content. The client (neovim) sends a didOpen notification with the content of the buffer to the server and every time the content is changed it sends the changes over. In our case, we don't need to send these notifications, they get sent automatically by nvim when we change the otter buffer because pyright is attached to that buffer (that's mostly what being attached entails). But if for some reason one of these notifications gets lost the server gets confused. Just something to keep in mind in case nothing else makes sense.

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 8, 2024

Also, I can not reproduce this with ./tests/debug_example.sh 05.norg
image
image

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 8, 2024

What file do you experience the issue with and how do you activate otter?

@benlubas
Copy link
Contributor Author

benlubas commented Jul 8, 2024

Here's the file:

file
@code python
y = []
y.pop()
if True:
  y.append(1)
@end

* Heading
  @code python
  print("hi there")
  x = []
  y_2 = x.copy()

  y.pop()

  while True:
    x.clear()
    for i in range(10):
      x.append(i)
    break
  @end

I activate it with a dev version of the Neorg otter integration, which is here. The relevant lines are:

otter.activate(
    module.config.public.languages, -- I have set to { "python", "lua" }
    module.config.public.completion.enabled, -- true
    module.config.public.diagnostics.enabled, -- true
    nil
)

The above integration is only providing user commands and making sure that handle_leading_whitespace is set to true.

@benlubas
Copy link
Contributor Author

benlubas commented Jul 8, 2024

I can print and inspect in a little bit, I've got a bunch of random stuff to do today, you don't have to look into this for now, I'll try to get a consistent reproduction

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 8, 2024

Ok. As another test, it is always interesting if activating otter manually after opening a file makes a difference compared to an autocommand or ftplugin, to rule out races with other plugins (like in this case: #154 (comment) ).

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 8, 2024

And while we are at it, I want to eventually take the otter.keeper.modify_position code and split it up explicitly for each request method, such that we don't unnecessarily check params for all sorts of positions for every request, so if destructuring this happens to become part of your debugging process I'd be happy about a PR :)

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 12, 2024

Something else must be going on here. If I take your file and and just add an autocommand to activate otter for norg

vim.api.nvim_create_autocmd({ "BufReadPost" }, {
    desc = "Activate Otter on Buf Enter",
    pattern = "*.norg",
    group = vim.api.nvim_create_augroup("NorgOtter", {}),
    callback = function(_)
      require'otter'.activate()
    end,
})

it just works. Same as activating manually.
However, I don't have anything else configured for Norg. Does the Norg plugin modify the buffer in any way after opening?

@jmbuhr
Copy link
Owner

jmbuhr commented Jul 12, 2024

Btw. as you can see in the autocommand, you don't have to necessarily pass languages to otter.activate, it creates otters for all languages found (and for which it knows file extensions) by default.

@benlubas
Copy link
Contributor Author

Neorg doesn't alter the buffer after opening.

@benlubas
Copy link
Contributor Author

I'm unable to reproduce it in ~5 minutes of playing around with it. I'll reopen if I find a reproduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants