Shougo / dpp.vim

Dark powered plugin manager for Vim/neovim
MIT License
128 stars 5 forks source link

plugin-local ftplugins are overwritten by global ftplugins #29

Closed 4513ECHO closed 1 month ago

4513ECHO commented 1 month ago

Problems summary

plugin-local ftplugins are overwritten by global ftplugins.

Expected

Merged correctly.

Environment Information

Neovim ``` NVIM v0.11.0-dev-3725+g0c2860d9e-Homebrew Build type: Release LuaJIT 2.1.1720049189 Run ":verbose version" for more info ```
Vim ``` VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Aug 04 2024 17:57:44) macOS 版 - arm64 適用済パッチ: 1-660 Compiled by Homebrew Huge 版 without GUI. 機能の一覧 有効(+)/無効(-) +acl +file_in_path +mouse_urxvt -tag_any_white +arabic +find_in_path +mouse_xterm -tcl +autocmd +float +multi_byte +termguicolors +autochdir +folding +multi_lang +terminal -autoservername -footer -mzscheme +terminfo -balloon_eval +fork() +netbeans_intg +termresponse +balloon_eval_term +gettext +num64 +textobjects -browse -hangul_input +packages +textprop ++builtin_terms +iconv +path_extra +timers +byte_offset +insert_expand +perl +title +channel +ipv6 +persistent_undo -toolbar +cindent +job +popupwin +user_commands -clientserver +jumplist +postscript +vartabs +clipboard +keymap +printer +vertsplit +cmdline_compl +lambda +profile +vim9script +cmdline_hist +langmap -python +viminfo +cmdline_info +libcall +python3 +virtualedit +comments +linebreak +quickfix +visual +conceal +lispindent +reltime +visualextra +cryptv +listcmds +rightleft +vreplace +cscope +localmap +ruby +wildignore +cursorbind +lua +scrollbind +wildmenu +cursorshape +menu +signs +windows +dialog_con +mksession +smartindent +writebackup +diff +modify_fname +sodium -X11 +digraphs +mouse +sound -xattr -dnd -mouseshape +spell -xfontset -ebcdic +mouse_dec +startuptime -xim +emacs_tags -mouse_gpm +statusline -xpm +eval -mouse_jsbterm -sun_workshop -xsmp +ex_extra +mouse_netterm +syntax -xterm_clipboard +extra_search +mouse_sgr +tag_binary -xterm_save -farsi -mouse_sysmouse -tag_old_static システム vimrc: "$VIM/vimrc" ユーザー vimrc: "$HOME/.vimrc" 第2ユーザー vimrc: "~/.vim/vimrc" 第3ユーザー vimrc: "$XDG_CONFIG_HOME/vim/vimrc" ユーザー exrc: "$HOME/.exrc" デフォルトファイル: "$VIMRUNTIME/defaults.vim" 省略時の $VIM: "/Users/234531sch/Library/homebrew/share/vim" コンパイル: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -I/Users/234531sch/Library/homebrew/Cellar/libsodium/1.0.20/include -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 リンク: clang -o vim -lm -lncurses -L/Users/234531sch/Library/homebrew/Cellar/libsodium/1.0.20/lib -lsodium -liconv -lintl -framework AppKit -L/Users/234531sch/Library/homebrew/opt/lua/lib -llua5.4 -mmacosx-version-min=14.4 -fstack-protector-strong -L/Users/234531sch/Library/homebrew/opt/perl/lib/perl5/5.38/darwin-thread-multi-2level/CORE -lperl -L/Users/234531sch/Library/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin -lpython3.12 -lintl -framework CoreFoundation -lruby.3.3 -L/Users/234531sch/Library/homebrew/Cellar/ruby/3.3.4/lib ```

Provide a minimal init.vim/vimrc without plugin managers (Required!)

set runtimepath^=/path/to/github.com/vim-denops/denops.vim
set runtimepath^=/path/to/github.com/Shougo/dpp.vim
const s:dpp_dir = fnamemodify('./cache', ':p')
const s:dpp_ts = fnamemodify('./dpp.ts', ':p')

if dpp#min#load_state(s:dpp_dir)
  autocmd User DenopsReady call dpp#make_state(s:dpp_dir, s:dpp_ts)
  autocmd User Dpp:makeStatePost quit
endif
import {
  BaseConfig,
  type ConfigArguments,
  type ConfigReturn,
} from "jsr:@shougo/dpp-vim@^1.1.0/config";
import type { MultipleHook, Plugin } from "jsr:@shougo/dpp-vim@^1.1.0/types";
import { mergeFtplugins } from "jsr:@shougo/dpp-vim@^1.1.0/utils";

type Toml = {
  ftplugins?: Record<string, string>;
  hooks_file?: string;
  multiple_hooks?: MultipleHook[];
  plugins?: Plugin[];
};

function mergeToml(tomls: Toml[]): ConfigReturn {
  return {
    ftplugins: tomls.map((x) => x.ftplugins).reduce((acc, x) => {
      if (!x) return acc;
      if (!acc) return x;
      mergeFtplugins(acc, x);
      return acc;
    }),
    hooksFiles: tomls.map((x) => x.hooks_file)
      .filter((x) => typeof x === "string"),
    multipleHooks: tomls.flatMap((x) => x.multiple_hooks ?? []),
    plugins: tomls.flatMap((x) => x.plugins ?? []),
  };
}

export class Config extends BaseConfig {
  override config(_args: ConfigArguments): ConfigReturn {
    const { plugins, ftplugins } = mergeToml([
      { plugins: [{ name: "hoge", ftplugin: { help: "echo 'plugins 1'" } }] },
      { ftplugins: { help: "echo 'ftplugins'" } },
      { plugins: [{ name: "fuga", ftplugin: { help: "echo 'plugins 2'" } }] },
    ]);

    return {
      ftplugins,
      plugins,
    };
  }
}

How to reproduce the problem from neovim/Vim startup (Required!)

  1. Run nvim -nNu init.vim -i NONE --headless or vim -nNu init.vim -i NONE
  2. View cache/{nvim,vim}/.dpp/after/ftplugin/help.vim
if 'b:undo_ftplugin'->exists()
  let b:undo_ftplugin ..= '|'
else
  let b:undo_ftplugin = ''
endif
echo 'ftplugins'

Screenshot (if possible)

None.

Upload the log messages by :redir and :message (if errored)

None.

Shougo commented 1 month ago

OK. I get it.

Plugins ftplugins are merged when it is installed.

Shougo commented 1 month ago

I have added the description. It is feature.