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

Can't do java code formatting. #229

Closed
kametsun opened this issue Nov 10, 2023 · 3 comments
Closed

Can't do java code formatting. #229

kametsun opened this issue Nov 10, 2023 · 3 comments
Labels

Comments

@kametsun
Copy link

Describe the bug
When attempting to format a file using Vim with the specified command, the error message "Error formatting file: Vim(let):E282: Cannot read from 'C:\Users\J22011\AppData\Local\Temp\V3F7F37.tmp'" is encountered.

To Reproduce
Minimal vimrc: https://raw.githubusercontent.com/kametsun/vim-setting/main/.vimrc

Steps to reproduce the behavior:
[

  1. Go to ':FormatCode google-java-format'
  2. Click on ''
  3. Scroll down to ''
  4. See error 'message "Error formatting file: Vim(let):E282: Cannot read from 'C:\Users\J22011\AppData\Local\Temp\V3F7F37.tmp'" is encountered.'
    ]

Expected behavior
We expect the file to be formatted without error and the changes to be saved successfully.

OS (version)
Windows 11 Pro 23H2
Additional context
PS C:\workspace-java> vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 28 2022 12:30:17)

@kametsun kametsun added the bug label Nov 10, 2023
@dbarnett
Copy link
Contributor

Can you format other languages?

Looks like either vim can't find its own tmp files on your Windows setup OR the particular formatter command you set up there with your jar file is failing to output code to tmp and codefmt is only surfacing a confusing secondary error that means "command failed to produce output".

@kametsun
Copy link
Author

I can't format other languages. I tried js-beautify.

`" 構文チェック
syntax enable

"---------------
"エンコーディング
"---------------
set encoding=UTF-8
set fileencoding=UTF-8
set termencoding=UTF-8

"----------------
" スクロール
"----------------
" スクロール時に下が見えるようにする
set scrolloff=5

"----------------
" ファイル
"----------------
" スワップファイルを作らない
set noswapfile
" バックアップファイルを作らない
set nowritebackup
" バックアップをしない
set nobackup
" 自動保存を有効にする
set autowrite
" ファイルを上書きする前にバックアップを作ることを無効化
set nowritebackup
" 保存されていないファイルがあるときでも別のファイルを開ける
set hidden
"----------------
" ターミナル
"----------------
" ターミナル接続を高速化
set ttyfast

"----------------
" エディタ
"----------------
" 長い行を折り返さない
set nowrap
" タイトルを表示
set title
" 行番号を表示
set number
" 対応する括弧に一瞬移動
set showmatch
" 対応する括弧への移動時間
set matchtime=1
" タブキーで補完を有効にする
set wildmode=list:full
" 折り返し表示を有効にする
set wrap
" ウィンドウの幅に合わせて折り返しを行う
set linebreak
" vim の矩形選択で文字が無くても右へ進める
set virtualedit=block
" 全角文字専用の設定
set ambiwidth=double
" エラーメッセージの表示時にビープを鳴らさない
set noerrorbells
" コマンドラインの履歴を10000件保存する
set history=10000
" コメントの色を水色
hi Comment ctermfg=3
" カーソルラインを表示
"set cursorline
" 括弧補完
set backspace=indent,eol,start
inoremap { {}
inoremap { {}
inoremap ( ()
inoremap ( ()
inoremap [ []
inoremap [ []
inoremap " ""
inoremap ' ''

"----------------
" シンタックスハイライト
"----------------

"----------------
" インデント・タブ
"----------------
" 改行時に、前の行と同じ数だけ自動でインデントする
set autoindent
" 自動でインデントする際、「{」等のブロックに応じてインデントを調整
set smartindent
" タブ文字の空白数
set tabstop=4
" タブキーを押したときに挿入される空白数
set softtabstop=4
" ファイル内にあるタブ文字の表示幅
set tabstop=4
" 改行時に入力された行の末尾に合わせて次の行のインデントを増減する
set smartindent
" vimで読み込みのときにtabの幅をスペース4個分にする
set shiftwidth=4
"----------------
" コマンドライン
"----------------
" コマンドラインの高さ
set cmdheight=2
" 補完候補を一覧表示
set wildmenu
" 入力中のコマンドを表示する
set showcmd
"----------------
" 検索
"----------------
" 検索文字列をハイライト
set hlsearch
" 大文字・小文字を区別しない
set ignorecase
" インクリメンタルサーチ(一文字入力するごとに検索)
set incsearch
" 検索がファイル末尾まで進んだら、ファイル先頭から再び検索
set wrapscan

"----------------
" java用
"----------------
:let java_highlight_all=1
:let java_highlight_debug=1
:let java_space_errors=1
:let java_highlight_functions=1

"----------------
" vim-plugの設定
"----------------
call plug#begin('~/.vim/plugged')
" 入れたいプラグインを書く
Plug 'google/vim-maktaba'
Plug 'google/vim-codefmt'
Plug 'google/vim-glaive'
" JavaScript, HTML, CSS Formater
Plug 'maksimr/vim-jsbeautify'
call plug#end()

call glaive#Install()
Glaive codefmt google_java_executable="java -jar $HOME/google-java-format-1.18.1-all-deps.jar"

augroup autoformat_settings
autocmd FileType bzl AutoFormatBuffer buildifier
autocmd FileType c,cpp,proto,javascript,arduino AutoFormatBuffer clang-format
autocmd FileType dart AutoFormatBuffer dartfmt
autocmd FileType go AutoFormatBuffer gofmt
autocmd FileType gn AutoFormatBuffer gn
autocmd FileType html,css,sass,scss,less,json AutoFormatBuffer js-beautify
autocmd FileType java AutoFormatBuffer google-java-format
autocmd FileType python AutoFormatBuffer yapf
" Alternative: autocmd FileType python AutoFormatBuffer autopep8
autocmd FileType rust AutoFormatBuffer rustfmt
autocmd FileType vue AutoFormatBuffer prettier
autocmd FileType swift AutoFormatBuffer swift-format
augroup END
`

:FormatCode google-java-format
=> Error formatting file: Vim(let):E282: Cannot read from"C:\Users\J22011\AppData\Local\Temp\VJB687D.tmp"

I searched "C:\Users\J22011\AppData\Local\Temp\VJB687D.tmp", but could find no such file.

The java runtime environment exists.JDK21.01

@dbarnett
Copy link
Contributor

Duplicate of #86.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants