diff --git a/autoload/traqvim/command.vim b/autoload/traqvim/command.vim index 01d5b81..83b7fa4 100644 --- a/autoload/traqvim/command.vim +++ b/autoload/traqvim/command.vim @@ -50,14 +50,25 @@ function traqvim#command#channel(args) abort elseif a:args[0] ==# 'reload' call denops#request('traqvim', 'reload', [bufnr(), bufname()]) elseif a:args[0] ==# 'forward' - call denops#request('traqvim', 'messageForwad', [bufnr(), bufname()]) + call denops#request('traqvim', 'messageForward', [bufnr(), bufname()]) elseif a:args[0] ==# 'back' call denops#request('traqvim', 'messageBack', [bufnr(), bufname()]) endif endfunction function traqvim#command#channelComplete(arglead, cmdline) abort - if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(split(a:cmdline)) >= 3 + " ['Traq', 'channel', ...] + let cmds = split(a:cmdline) + " openの場合はチャンネル名を補完 + if len(cmds) >= 3 && cmds[2] ==# 'open' + if len(cmds) == 3 + return ['#'] + elseif len(cmds) == 4 + let channels = denops#request('traqvim', 'channelList', []) + return channels->map({_, v -> v['path']})->matchfuzzy(a:arglead) + endif + endif + if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(cmds) >= 3 return [] endif return g:traqvim#command#subcommands.channel.args->copy()->filter({_, v -> v =~? '^' . a:arglead}) diff --git a/denops/traqvim/main.ts b/denops/traqvim/main.ts index 1f0e97f..a3ba5f3 100644 --- a/denops/traqvim/main.ts +++ b/denops/traqvim/main.ts @@ -1,6 +1,7 @@ import { OAuth } from "./oauth.ts"; import { channelMessageOptions, + channelsRecursive, channelTimeline, channelUUID, homeChannelId, @@ -29,7 +30,7 @@ import { actionYankMessageLink, actionYankMessageMarkdown, } from "./action.ts"; -import { ChannelMessageBuffer, Message } from "./type.d.ts"; +import { Channel, ChannelMessageBuffer, Message } from "./type.d.ts"; import { api } from "./api.ts"; import { isMessage } from "./type_check.ts"; @@ -378,4 +379,10 @@ export async function main(denops: Denops) { return; }, }; + + // apiっぽいやつ + denops.dispatcher["channelList"] = async (): Promise => { + const channels = await channelsRecursive(); + return channels; + }; }