GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix bug · chxuan/cpp-mode@1cb80a6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • autoload/cppmode
    • go_to_definition.vim
    • go_to_fun_impl.vim
    • util.vim
  • ftplugin
    • cpp.vim
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cpp-mode: A C++ IDE for vim
2525

2626
生成函数实现或变量定义,和`:CopyCode`结合使用
2727

28-
- `:GoToDefinition`
28+
- `:GoToFunImpl`
2929

3030
转到函数实现,该功能可替代ycm提供的转到函数实现(因为ycm转到函数实现经常不成功)
3131

Collapse file

‎autoload/cppmode/go_to_definition.vim‎

Copy file name to clipboardExpand all lines: autoload/cppmode/go_to_definition.vim
-68Lines changed: 0 additions & 68 deletions
This file was deleted.
Collapse file

‎autoload/cppmode/go_to_fun_impl.vim‎

Copy file name to clipboard
+136Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
" ==============================================================
2+
" Author: chxuan <[email protected]>
3+
" Repository: https://github.com/chxuan/cppmode
4+
" Create Date: 2018-05-31
5+
" License: MIT
6+
" ==============================================================
7+
8+
" 转到定义
9+
function! cppmode#go_to_fun_impl#go_to_fun_impl()
10+
if <sid>go_to_impl_in_impl_file() == -1
11+
if <sid>go_to_impl_in_head_file() == -1
12+
echo "Not found function implement"
13+
endif
14+
endif
15+
endfunction
16+
17+
" 在实现文件查找函数实现
18+
function! s:go_to_impl_in_impl_file()
19+
let file_path = <sid>get_impl_file_path()
20+
21+
if cppmode#util#is_exist(file_path)
22+
return <sid>go_to_impl_with_class(file_path)
23+
endif
24+
25+
return -1
26+
endfunction
27+
28+
" 在头文件查找函数实现
29+
function! s:go_to_impl_in_head_file()
30+
let file_path = <sid>get_head_file_path()
31+
32+
if cppmode#util#is_exist(file_path) && <sid>go_to_impl_with_class(file_path) == -1
33+
return <sid>go_to_impl_not_with_class(file_path)
34+
endif
35+
36+
return -1
37+
endfunction
38+
39+
" 获得实现文件路径
40+
function! s:get_impl_file_path()
41+
let file_path = cppmode#util#get_current_file_path()
42+
let suffix = cppmode#util#get_current_file_suffix()
43+
44+
if suffix == "cpp"
45+
return file_path
46+
elseif suffix == "h"
47+
return cppmode#util#substr(file_path, 0, len(file_path) - 1) . "cpp"
48+
else
49+
return ""
50+
endif
51+
52+
endfunction
53+
54+
" 获得头文件路径
55+
function! s:get_head_file_path()
56+
let file_path = cppmode#util#get_current_file_path()
57+
let suffix = cppmode#util#get_current_file_suffix()
58+
59+
if suffix == "h"
60+
return file_path
61+
elseif suffix == "cpp"
62+
return cppmode#util#substr(file_path, 0, len(file_path) - 3) . "h"
63+
else
64+
return ""
65+
endif
66+
67+
endfunction
68+
69+
" 转到函数实现
70+
function! s:go_to_impl_with_class(file_path)
71+
let fun_name = cppmode#util#get_current_cursor_word()
72+
let lines = cppmode#util#read_file(a:file_path)
73+
let row_num = <sid>get_row_num_with_class(lines, fun_name)
74+
75+
if row_num != -1
76+
if a:file_path != cppmode#util#get_current_file_path()
77+
call cppmode#util#open_tab(a:file_path)
78+
endif
79+
80+
let text = cppmode#util#get_row_text(row_num)
81+
let col_num = cppmode#util#find(text, "::" . fun_name . "(") + 3
82+
call cppmode#util#set_cursor_position(row_num, col_num)
83+
84+
return 1
85+
endif
86+
87+
return -1
88+
endfunction
89+
90+
" 转到函数实现
91+
function! s:go_to_impl_not_with_class(file_path)
92+
let fun_name = cppmode#util#get_current_cursor_word()
93+
let lines = cppmode#util#read_file(a:file_path)
94+
let row_num = <sid>get_row_num_not_with_class(lines, fun_name)
95+
96+
if row_num != -1
97+
if a:file_path != cppmode#util#get_current_file_path()
98+
call cppmode#util#open_tab(a:file_path)
99+
endif
100+
101+
let text = cppmode#util#get_row_text(row_num)
102+
let col_num = cppmode#util#find(text, fun_name) + 1
103+
call cppmode#util#set_cursor_position(row_num, col_num)
104+
105+
return 1
106+
endif
107+
108+
return -1
109+
endfunction
110+
111+
" 获得行号
112+
function! s:get_row_num_with_class(lines, fun_name)
113+
let target = "::" . a:fun_name . "("
114+
115+
for i in range(0, len(a:lines) - 1)
116+
if cppmode#util#is_contains(a:lines[i], target)
117+
return i + 1
118+
endif
119+
endfor
120+
121+
return -1
122+
endfunction
123+
124+
" 获得行号
125+
function! s:get_row_num_not_with_class(lines, fun_name)
126+
let target = a:fun_name . "("
127+
128+
for i in range(0, len(a:lines) - 1)
129+
if cppmode#util#is_contains(a:lines[i], target) && (cppmode#util#is_contains(a:lines[i], "{") && cppmode#util#is_contains(a:lines[i], "}") || cppmode#util#is_contains(a:lines[i + 1], "{"))
130+
return i + 1
131+
endif
132+
endfor
133+
134+
return -1
135+
endfunction
136+
Collapse file

‎autoload/cppmode/util.vim‎

Copy file name to clipboardExpand all lines: autoload/cppmode/util.vim
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function! cppmode#util#substr(str, start, count)
141141
endfunction
142142

143143
" 判断文件是否存在
144-
function! cppmode#util#is_file_exists(file_path)
144+
function! cppmode#util#is_exist(file_path)
145145
return filereadable(a:file_path)
146146
endfunction
147147

Collapse file

‎ftplugin/cpp.vim‎

Copy file name to clipboardExpand all lines: ftplugin/cpp.vim
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let s:is_fun = 0
1515

1616
command! -nargs=0 CopyCode call <sid>copy_code()
1717
command! -nargs=0 PasteCode call <sid>paste_code()
18-
command! -nargs=0 GoToDefinition call cppmode#go_to_definition#go_to_definition()
18+
command! -nargs=0 GoToFunImpl call cppmode#go_to_fun_impl#go_to_fun_impl()
1919
command! -nargs=0 FormatFunParam call cppmode#format_fun_param#format_function_param()
2020
command! -nargs=0 FormatIf call cppmode#format_if#format_if()
2121
command! -nargs=0 Switch call cppmode#switch#switch_file()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.