Skip to content

fix(configs): prevent plugin-level setup() from overriding user configuration#300

Closed
pirey wants to merge 1 commit into
linrongbin16:masterfrom
pirey:master
Closed

fix(configs): prevent plugin-level setup() from overriding user configuration#300
pirey wants to merge 1 commit into
linrongbin16:masterfrom
pirey:master

Conversation

@pirey

@pirey pirey commented Apr 6, 2026

Copy link
Copy Markdown

Fix #299

The plugin automatically calls setup() in @plugin/gitlinker.lua without arguments. If users also call setup() with custom router configs in their Neovim config, the plugin-level call runs AFTER and overwrites the user's configuration.

Fix by adding early return in configs.setup() if Configs is already initialized.

Test Platforms

  • windows
  • macOS
  • linux

Test Hosts

Test Functions

  • Use GitLink(!) to copy git link (or open in browser).
  • Use GitLink(!) blame to copy the /blame link (or open in browser).
  • Use GitLink(!) default_branch to open the /main//master link in browser (or open in browser).
  • Use GitLink(!) current_branch to open the current branch link in browser (or open in browser).
  • Copy git link in a symlink directory of git repo.
  • Copy git link in an un-pushed git branch, and receive an expected error.
  • Copy git link in a pushed git branch but edited file, and receive a warning says the git link could be wrong.
  • Copy git link with 'file' and 'rev' parameters.

…guration

The plugin automatically calls setup() in @plugin/gitlinker.lua without
arguments. If users also call setup() with custom router configs in
their Neovim config, the plugin-level call runs AFTER and overwrites
the user's configuration.

Fix by adding early return in configs.setup() if Configs is already
initialized.
@linrongbin16

linrongbin16 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Thank you

The solution looks good, I haven't done any investigation about confliction between these two plugin initialization methods:

  • Built-in "plugin" folder plugin initialization by Neovim
  • Other plugin manager such as lazy.nvim, mini.deps, etc

The detection on "Configs._route" variable should work, I think it means "whehter this plugin is been alreay initialized".

Personally, I prefer using a boolean varaible to indicate whether this plugin is been initialized. Instead of using the "Configs._route" variable.

For example, we can have two methods:

  • Global variable "vim.g.gitlinker_loaded", the "vim.g.xxx_loaded" variable is a vim tradition to indicate a plugin is been intialized. But it is not safe (it can be modified by other scripts).
  • Add a new variable "Configs.__loaded" for gitlinker

@linrongbin16

linrongbin16 commented Apr 7, 2026

Copy link
Copy Markdown
Owner

I submit a PR #301 , @pirey would you take a look?


#301 is merged to master branch, please update the plugin and have a try

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.

Bug: setup() called in plugin/ overrides user's custom router configuration

2 participants