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

コマンドラインでチャンネル開く際に補完が出るよう変更 #97

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions autoload/traqvim/command.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
9 changes: 8 additions & 1 deletion denops/traqvim/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OAuth } from "./oauth.ts";
import {
channelMessageOptions,
channelsRecursive,
channelTimeline,
channelUUID,
homeChannelId,
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -378,4 +379,10 @@ export async function main(denops: Denops) {
return;
},
};

// apiっぽいやつ
denops.dispatcher["channelList"] = async (): Promise<Channel[]> => {
const channels = await channelsRecursive();
return channels;
};
}
Loading