Shougo / dpp.vim

Dark powered plugin manager for Vim/NeoVim
MIT License
134 stars 5 forks source link

The runtimepath of a merged plugin is added and duplicated with the cached .dpp runtimepath? #18

Closed kenji0923 closed 9 months ago

kenji0923 commented 9 months ago

Warning: I will close the issue without the minimal init.vim and the reproduction instructions.

Problems summary

The runtimepath stored in the state file contains runtimepaths of both an original plugin path and the cached directory (.dpp) to which the plugin was merged. In this issue, I try to manage vim-denops. By loading the state file, both of them are of course included in the loaded runtimepath, and I can see duplicated two titles of denops.txt at LOCAL ADDITIONS by :help command. Thanks in advance.

Expected

I expect the original plugin path, which I mean the path at which the plugin was cloned, would not be included in the runtimepath that was exported in the state file according to the document content dpp-merge.

Environment Information

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

vimrc

set nocompatible

" dpp

const s:dpp_config = '~/.vim/plugin/dpp.ts'

" Set dpp base path (required)
const s:dpp_base = '~/.cache/dpp/'

" Set dpp source path (required)
const s:denops_repo = 'vim-denops/denops.vim'
const s:dpp_repo = 'Shougo/dpp.vim'

const s:dpp_addon = [
            \ 'Shougo/dpp-protocol-git',
            \ 'Shougo/dpp-ext-toml',
            \ 'Shougo/dpp-ext-installer',
            \ 'Shougo/dpp-ext-lazy',
            \ ]

const s:dpp_manual_repo = [
            \ s:denops_repo,
            \ s:dpp_repo,
            \ ]

const s:dpp_manual_repo_source_url = 'github.com/'

function! s:get_repositry_path(repositry) abort
    return s:dpp_base .. 'repos/' .. s:dpp_manual_repo_source_url .. a:repositry
endfunction

const s:denops_src = s:get_repositry_path(s:denops_repo)
const s:dpp_src = s:get_repositry_path(s:dpp_repo)

for repositry in (s:dpp_manual_repo + s:dpp_addon)
    if ! isdirectory(repositry)
        let repositry_path = s:get_repositry_path(repositry)
        call mkdir(fnamemodify(expand(repositry_path), ':p:h'), "p")
        call system('git clone https://' .. s:dpp_manual_repo_source_url .. repositry .. ' ' .. repositry_path)
    endif
endfor

" Set dpp runtime path (required)
execute 'set runtimepath^=' .. s:dpp_src
for dpp_addon_path in s:dpp_addon
    let repositry_path = s:get_repositry_path(dpp_addon_path)
    execute 'set runtimepath^=' .. repositry_path
endfor

augroup dpp_custom
    autocmd! User Dpp:makeStatePost echom 'dpp has made a state'
augroup END

if s:dpp_base->dpp#min#load_state()
    " NOTE: dpp#make_state() requires denops.vim
    execute 'set runtimepath^=' .. s:denops_src
    autocmd User DenopsReady call dpp#make_state(s:dpp_base, s:dpp_config)
endif

filetype indent plugin on

if has('syntax')
    syntax on
endif

~/.vim/plugin/dpp.ts

import {
    BaseConfig,
    ContextBuilder,
    Dpp,
    Plugin,
} from "https://deno.land/x/dpp_vim@v0.0.9/types.ts";
import { Denops } from "https://deno.land/x/dpp_vim@v0.0.9/deps.ts";

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

type LazyMakeStateResult = {
    plugins: Plugin[];
    stateLines: string[];
};

export class Config extends BaseConfig {
    override async config(args: {
        denops: Denops;
        contextBuilder: ContextBuilder;
        basePath: string;
        dpp: Dpp;
    }): Promise<{
        checkFiles: string[];
        plugins: Plugin[];
        stateLines: string[];
    }> {
        args.contextBuilder.setGlobal({
            protocols: ['git'],
        });

        const [context, options] = await args.contextBuilder.get(args.denops);

        const config_directory = "~/.vim/plugin/";

        const check_files = new Map([
            [ "config", config_directory + "dpp.ts" ],
            [ "toml", config_directory + "dpp_plugin.toml" ]
        ]);

        // Load toml plugins
        const tomls: Toml[] = [];

        const toml = await args.dpp.extAction(
            args.denops,
            context,
            options,
            "toml",
            "load",
            {
                path: check_files.get("toml"),
                options: {
                    lazy: false,
                },
            },
        ) as Toml | undefined;

        if (toml) {
            tomls.push(toml);
        }

        // Merge toml results
        const recordPlugins: Record<string, Plugin> = {};
        const ftplugins: Record<string, string> = {};
        const hooks_files: string[] = [];

        for (const toml of tomls) {
            for (const plugin of toml.plugins) {
                recordPlugins[plugin.name] = plugin;
            }

            if (toml.ftplugins) {
                for (const filetype of Object.keys(toml.ftplugins)) {
                    if (ftplugins[filetype]) {
                        ftplugins[filetype] += `\n${toml.ftplugins[filetype]}`;
                    } else {
                        ftplugins[filetype] = toml.ftplugins[filetype];
                    }
                }
            }

            if (toml.hooks_file) {
                hooks_files.push(toml.hooks_file);
            }
        }

        return {
            checkFiles: [ ...check_files.values() ].concat(hooks_files),
            plugins: Object.values(recordPlugins),
            stateLines: []
        };
    }
}

~/.vim/plugin/dpp_plugin.toml

[[plugins]]
repo="vim-denops/denops.vim"

~/.cache/dpp/Vim/state.vim after makeState

if g:dpp#_cache_version !=# 1| throw "Cache version error" | endif
let [g:dpp#_plugins, g:dpp#ftplugin, g:dpp#_options, g:dpp#_check_files] = g:dpp#_cache
let g:dpp#_config_path = '/Users/kshu/.vim/plugin/dpp.ts'
let &runtimepath = '/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-ext-lazy,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-ext-installer,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-ext-toml,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-protocol-git,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp.vim,/Users/kshu/.vim,/Applications/MacVim.app/Contents/Resources/vim/vimfiles,/Users/kshu/.cache/dpp//repos/github.com/vim-denops/denops.vim,/Users/kshu/.cache/dpp/Vim/.dpp,/Applications/MacVim.app/Contents/Resources/vim/runtime,/Applications/MacVim.app/Contents/Resources/vim/vimfiles/after,/Users/kshu/.vim/after,/Users/kshu/.cache/dpp/Vim/.dpp/after'

Contents inside ~/.cache/dpp/Vim/.dpp by find .dpp -maxdepth 1

.dpp
.dpp/denops
.dpp/LICENSE
.dpp/deno.jsonc
.dpp/ftdetect
.dpp/plugin
.dpp/README.md
.dpp/.gitignore
.dpp/.github
.dpp/doc
.dpp/autoload
.dpp/after
.dpp/.gitmessage

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

  1. rm -rf ~/.cache/dpp
  2. vim
  3. :q
  4. vim
  5. :help
  6. :echom &runtimepath

Screenshot (if possible)

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

LOCAL ADDITIONS by :help

LOCAL ADDITIONS:                                local-additions
dpp-ext-lazy.txt        Lazy ext for dpp.vim
dpp-ext-installer.txt   Installer ext for dpp.vim
dpp-ext-toml.txt        Toml ext for dpp.vim
dpp-protocol-git.txt    git protocol for dpp.vim
dpp.txt         Dark powered plugin manager for Vim/neovim
denops.txt              An eco-system to write Vim/Neovim plugins in Deno
denops.txt              An eco-system to write Vim/Neovim plugins in Deno

:message

/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-ext-lazy,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-ext-installer,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-ext-toml,/Users/kshu/.cache/dpp/repos/github.com/Shougo/dpp-protocol-git,/Users/
kshu/.cache/dpp/repos/github.com/Shougo/dpp.vim,/Users/kshu/.vim,/Applications/MacVim.app/Contents/Resources/vim/vimfiles,/Users/kshu/.cache/dpp//repos/github.com/vim-denops/denops.vim,/Users/kshu/.cache/dpp/Vim/.dpp,/Applications/MacVim.app/Contents/Resou
rces/vim/runtime,/Applications/MacVim.app/Contents/Resources/vim/vimfiles/after,/Users/kshu/.vim/after,/Users/kshu/.cache/dpp/Vim/.dpp/after
Shougo commented 9 months ago

It is bug. Fixed.