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

Discussion sign and diagnostics #78

Merged

Conversation

johnybx
Copy link
Contributor

@johnybx johnybx commented Nov 1, 2023

👋 Hi,
this PR adds support for discussion sign and diagnostics. Diagnostics and signs are currently split on purpose ( even though the sign can be set also for diagnostic ) to have better control when multiline support will be added ( in this PR ). I will be testing this for few days to see if it works.

TODO:

  • ✔️ support multiline discussions for sign -> the idea is to have some main sign on line where the discussion is created and then other sign(s) ( maybe something like <--> but vertical ) if discussion is for multiple lines.
  • ✔️ support multiline discussions for diagnostics.
  • currently the discussions are refreshed when file is switched / loaded in reviewer -> do we need periodic updates ? it would be maybe convenient 🤔
    • ✔️ if we will have period updates maybe it is not great idea to always remove everything and set it again -> it is not hard to update to incremental updates. this does not seem to be needed
  • ✔️ actions for diagnostics / sign lines ( this may even be new PR ) for this PR I added function to jump to discussion tree where all other discussion actions are available.
  • ✔️ Maybe we should show sign and diagnostic for notes which match checksum ? Otherwise the discussion will have likely incorrect position 🤔

@johnybx johnybx force-pushed the discussion_sign_and_diagnostics branch from 9b4ce93 to be631f2 Compare November 5, 2023 21:50
@johnybx johnybx marked this pull request as ready for review November 5, 2023 23:33
Copy link
Owner

@harrisoncramer harrisoncramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incredibly awesome, left some comments!

lua/gitlab/actions/discussions.lua Outdated Show resolved Hide resolved
lua/gitlab/actions/discussions.lua Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
lua/gitlab/reviewer/init.lua Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lua/gitlab/actions/discussions.lua Show resolved Hide resolved
lua/gitlab/state.lua Outdated Show resolved Hide resolved
Copy link
Owner

@harrisoncramer harrisoncramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few more recommendations. This is looking very close. Nice work!

lua/gitlab/actions/discussions.lua Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@harrisoncramer
Copy link
Owner

I'm good to merge this @johnybx, is that okay with you? Let me know and will do it.

@harrisoncramer
Copy link
Owner

harrisoncramer commented Nov 8, 2023

Oh actually, an issue I've noticed -- for some reason when you try and use any other command from diffview such as DiffviewFileHistory outside of this plugin, it's now triggering your code to refresh_discussion_data which is causing an error!

Folks should be able to use Diffview outside of the context of this plugin!

This is the culprit:

M.set_callback_for_file_changed = function(callback)
  local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.file_changed", {})
  vim.api.nvim_create_autocmd("User", {
    pattern = { "DiffviewDiffBufWinEnter", "DiffviewViewEnter" },
    group = group,
    callback = callback,
  })
end

These events are triggered when using this plugin (diffview) even when not using gitlab.nvim which many users (including myself) may already be doing.

@johnybx
Copy link
Contributor Author

johnybx commented Nov 9, 2023

Ah I see, I think I can easily fix it by setting up autocommands at open and then doing cleanup on close. Other option would be to actually check which instance of diffview triggered the autocommand and only conditionally react - that would work even if you opened multiple instances of diffview. I will try to implement it this week 👍

@johnybx johnybx force-pushed the discussion_sign_and_diagnostics branch from 6f844be to a4b9f3e Compare November 12, 2023 15:05
Copy link
Contributor Author

@johnybx johnybx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the auto commands to trigger actions only if it is related to diffview opened by gitlab.nvim and also tried having gitlab review and normal diffview and didn't noticed any errors.
I'll be for sure doing multiple reviews next week so I will be testing more for sure 👍

cmd/git.go Outdated
https://git@gitlab.com/namespace/subnamespace/dummy-test-repo.git
git@git@gitlab.com:namespace/subnamespace/dummy-test-repo.git
*/
re := regexp.MustCompile(`(?:https?:\/\/|ssh:\/\/|git@)(?:[^\/:]+)[\/:](.*)\/([^\/]+?)(?:\.git)?$`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that on many repositories I often use very different format of url ( I don't set it manually ) so I updated regexp to match urls in comment. I tested this manually and also here. The main problem was the assumption that namespace is just one word ( ([^\/]+ ) but namespace is everything in URI till the project name.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was fixed by #87 which caused a merge conflict with this branch, so we can go with that branch's changes here

Copy link
Contributor Author

@johnybx johnybx Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolved the conflict here but my regexp is more extended - the previous version was for example missing ssh:// and also the .git extension is optional and not necessary ( have few repos like that ). I run tests and nothing was broken - maybe would be worth extend tests for more cases 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added tests.

@harrisoncramer
Copy link
Owner

If you make my suggested changes and resolve the merge conflict then I'll merge this! Thank you for dealing with double conflicts here, appreciate this truly awesome contribution!

@johnybx johnybx force-pushed the discussion_sign_and_diagnostics branch from a4b9f3e to 65d4a4a Compare November 13, 2023 13:49
@johnybx
Copy link
Contributor Author

johnybx commented Nov 13, 2023

I resolved conflicts but I don't see your suggested changes 🤔. I see only resolved comments - is it within resolved comments ?

lua/gitlab/reviewer/diffview.lua Outdated Show resolved Hide resolved
lua/gitlab/reviewer/diffview.lua Show resolved Hide resolved
cmd/git.go Outdated
https://git@gitlab.com/namespace/subnamespace/dummy-test-repo.git
git@git@gitlab.com:namespace/subnamespace/dummy-test-repo.git
*/
re := regexp.MustCompile(`(?:https?:\/\/|ssh:\/\/|git@)(?:[^\/:]+)[\/:](.*)\/([^\/]+?)(?:\.git)?$`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was fixed by #87 which caused a merge conflict with this branch, so we can go with that branch's changes here

@harrisoncramer
Copy link
Owner

I resolved conflicts but I don't see your suggested changes 🤔. I see only resolved comments - is it within resolved comments ?

I'm sorry, the review was never submitted, you should see them now

@harrisoncramer harrisoncramer merged commit 58c3dcc into harrisoncramer:main Nov 13, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants