3 changed files with 85 additions and 65 deletions
@ -1,83 +1,95 @@ |
|||||
let b:ale_fixers = ['clangtidy', 'clang-format', 'remove_trailing_lines', 'trim_whitespace'] |
let b:ale_fixers = { |
||||
let b:ale_linters = ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder'] |
\ 'cpp' : [ |
||||
|
\ 'clangtidy', |
||||
|
\ 'clang-format', |
||||
|
\ 'remove_trailing_lines', |
||||
|
\ 'trim_whitespace' |
||||
|
\ ] |
||||
|
\ } |
||||
|
|
||||
|
let b:ale_linters = { |
||||
|
\ 'cpp' : [ |
||||
|
\ 'cc', |
||||
|
\ 'ccls', |
||||
|
\ 'clangcheck', |
||||
|
\ 'clangd', |
||||
|
\ 'clangtidy', |
||||
|
\ 'clazy', |
||||
|
\ 'cppcheck', |
||||
|
\ 'cpplint', |
||||
|
\ 'cquery', |
||||
|
\ 'cspell', |
||||
|
\ 'flawfinder' |
||||
|
\ ] |
||||
|
\ } |
||||
|
|
||||
" Function to find the project root |
|
||||
function! FindProjectRoot() |
function! FindProjectRoot() |
||||
let l:current_dir = expand('%:p:h') |
let l:current_dir = expand('%:p:h') |
||||
while l:current_dir != "/" |
while l:current_dir != "/" |
||||
if filereadable(l:current_dir . "/main.cpp") |
if filereadable(l:current_dir . "/main.cpp") |
||||
return l:current_dir |
return l:current_dir |
||||
endif |
endif |
||||
let l:current_dir = fnamemodify(l:current_dir, ':h') |
let l:current_dir = fnamemodify(l:current_dir, ':h') |
||||
endwhile |
endwhile |
||||
return "" |
return "" |
||||
endfunction |
endfunction |
||||
|
|
||||
" Function to compile the project |
|
||||
function! CompileProject(debug) |
function! CompileProject(debug) |
||||
let l:project_root = FindProjectRoot() |
let l:project_root = FindProjectRoot() |
||||
if l:project_root == "" |
if l:project_root == "" |
||||
echo "main.cpp not found in any parent directory." |
echo "main.cpp not found in any parent directory." |
||||
return |
return |
||||
endif |
endif |
||||
let l:main_file = l:project_root . "/main.cpp" |
let l:main_file = l:project_root . "/main.cpp" |
||||
|
|
||||
" Extract the project directory name |
let l:project_name = fnamemodify(l:project_root, ':t') |
||||
let l:project_name = fnamemodify(l:project_root, ':t') |
let l:output_file = l:project_root . "/" . l:project_name |
||||
let l:output_file = l:project_root . "/" . l:project_name |
|
||||
|
|
||||
let l:warning_flags = "-Wall -Weffc++ -Wextra -Wconversion -Wsign-conversion" |
let l:warning_flags = "-Wall -Weffc++ -Wextra -Wconversion -Wsign-conversion" |
||||
let l:disable_extension_flags = "-pedantic-errors" |
let l:disable_extension_flags = "-pedantic-errors" |
||||
let l:debug_flags = a:debug ? "-ggdb" : "-O2 -DNDEBUG" |
let l:debug_flags = a:debug ? "-ggdb" : "-O2 -DNDEBUG" |
||||
let l:standard_flag = "-std=c++20" |
let l:standard_flag = "-std=c++20" |
||||
|
|
||||
let l:compile_cmd = |
let l:compile_cmd = |
||||
\ "g++" . " " . |
\ "g++" . " " . |
||||
\ l:standard_flag . " " . |
\ l:standard_flag . " " . |
||||
\ l:warning_flags . " " . |
\ l:warning_flags . " " . |
||||
\ l:disable_extension_flags . " " . |
\ l:disable_extension_flags . " " . |
||||
\ l:debug_flags . " " . |
\ l:debug_flags . " " . |
||||
\ l:main_file . " " . |
\ l:main_file . " " . |
||||
\ "-o" . " " . l:output_file |
\ "-o" . " " . l:output_file |
||||
|
|
||||
" Run the compile command and capture the output |
" Run the compile command and capture the output |
||||
let l:output = system(l:compile_cmd) |
let l:output = system(l:compile_cmd) |
||||
|
|
||||
" Check if the compilation was successful |
" Check if the compilation was successful |
||||
if v:shell_error |
if v:shell_error |
||||
echo "Compilation failed:" |
echo "Compilation failed:" |
||||
echo l:output |
echo l:output |
||||
else |
else |
||||
echo "Compilation successful. Output: " . l:output_file |
echo "Compilation successful. Output: " . l:output_file |
||||
endif |
endif |
||||
endfunction |
endfunction |
||||
|
|
||||
" Function to run the compiled project |
|
||||
function! RunProject() |
function! RunProject() |
||||
let l:project_root = FindProjectRoot() |
let l:project_root = FindProjectRoot() |
||||
if l:project_root == "" |
if l:project_root == "" |
||||
echo "Project root not found." |
echo "Project root not found." |
||||
return |
return |
||||
endif |
endif |
||||
|
|
||||
" Extract the project directory name |
let l:project_name = fnamemodify(l:project_root, ':t') |
||||
let l:project_name = fnamemodify(l:project_root, ':t') |
let l:output_file = l:project_root . "/" . l:project_name |
||||
let l:output_file = l:project_root . "/" . l:project_name |
|
||||
|
|
||||
" Check if the output file exists |
if !filereadable(l:output_file) |
||||
if !filereadable(l:output_file) |
echo "Output file not found. Please compile the project first." |
||||
echo "Output file not found. Please compile the project first." |
return |
||||
return |
endif |
||||
endif |
|
||||
|
|
||||
" Run the compiled output file |
let l:run_cmd = "!" . l:output_file |
||||
let l:run_cmd = "!" . l:output_file |
execute l:run_cmd |
||||
execute l:run_cmd |
|
||||
endfunction |
endfunction |
||||
|
|
||||
" Create the Compile command |
|
||||
command! -nargs=0 Compile call CompileProject(1) |
command! -nargs=0 Compile call CompileProject(1) |
||||
command! -nargs=0 CompileRelease call CompileProject(0) |
command! -nargs=0 CompileRelease call CompileProject(0) |
||||
|
command! -nargs=0 Run call RunProject() |
||||
" Create the Run command |
|
||||
command! Run call RunProject() |
|
||||
|
@ -1,2 +1,9 @@ |
|||||
set foldmethod=expr |
let g:ale_python_flake8_options = '--ignore=E501,E402' |
||||
set foldexpr=nvim_treesitter#foldexpr() |
|
||||
|
let g:ale_linters = { |
||||
|
\ 'python': ['flake8'], |
||||
|
\ } |
||||
|
|
||||
|
let g:ale_fixers = { |
||||
|
\ 'python': ['black'] |
||||
|
\ } |
||||
|
Loading…
Reference in new issue