Comments (5)
It seems that ktlint can already clean up imports while formatting. How about utilizing it in the project as an optional formatter?
from kotlin-language-server.
function! ApplyImportQuickFixes()
let l:currentCursorPosition = getcurpos()
let l:addedImports = {}
while 1
let l:quickfixes = CocAction('quickfixes')
let l:importQuickfixes = filter(l:quickfixes, 'v:val.title =~ "^Import "')
if len(l:importQuickfixes) <= 0
break
endif
let l:importTitle = l:importQuickfixes[0].title
if has_key(l:addedImports, l:importTitle)
continue
endif
let l:addedImports[l:importTitle] = 1
call cursor(l:importQuickfixes[0].diagnostics[0].range.start.line + 1, l:importQuickfixes[0].diagnostics[0].range.start.character + 1)
call CocAction('doQuickfix', l:importQuickfixes[0])
endwhile
call setpos('.', l:currentCursorPosition)
endfunction
autocmd BufWritePre *.kt call ApplyImportQuickFixes()
I hope it's not too out of scope to post it here. And again it's not ideal and untested. Using Vim 8.x with coc.nvim and coc-kotlin.
As far as contributing goes, I might just try to cobble something together, but even if I manage I highly doubt it will be adequate enough for a pull request.
Thank you for the swift response and the insight!
from kotlin-language-server.
There seems to be some upstream support in LSP for organizing imports, see the docs on code actions (specifically the source.organizeImports
code action kind). Not sure if this directly maps to VSCode's built-in editor.action.organizeImports
, which binds to Shift + Alt + O by default, this would be something worth investigating.
from kotlin-language-server.
Iām currently using a Quick Fix hack to make this happen, but is there any news on the proper implementation of this?
from kotlin-language-server.
Iām currently using a Quick Fix hack to make this happen, but is there any news on the proper implementation of this?
There is a quick fix included to add missing imports. Other than that, I don't know... The activity in this project is fairly low, and the chief maintainer doesn't seem to have time for it. (+ strong opinions on how things should be, so I have grown weary of merging bigger PRs because of it). I have lost most of my motivation to work on it, and I think the same applies to many of our former contributors.
Feel free to try to implement a version yourself š Also, feel free to share your quick fix hack! It might help other people. From experience, I know that it is the small hacks and extensions in editors that make this language server more usable.
from kotlin-language-server.
Related Issues (20)
- Server initialization failed. HOT 1
- Extend "Add missing import" code action to suggest "static methods"/functions
- C interoperability support? HOT 3
- Crash on windows
- Automatically generate "thank you" message for all contributors in release script
- Dependency module <dependencies of main> was not initialized by the time contents of dependent module <dependencies of main> were queried HOT 1
- Add code completion for labels
- JsonSyntaxException on startup HOT 6
- Re-add semantic tokens for string literals without covering up interpolations
- Support java 21 HOT 1
- Despite best efforts a sea of red in vscode: MISSING_BUILT_IN_DECLARATION HOT 1
- language server won`t start after update gradle from 8.5 to 8.6 HOT 2
- Neovim + Android + Mason: Unresolved references for certain android dependencies
- Support for multi-module project HOT 4
- Extension fails on Ubuntu devcontainer - couldn't create connection to server. HOT 2
- java.util.concurrent.TimeoutException: Unable to connect language server
- Feature - disable extension on per-file basis to mitigate `Unresolved reference:` errors HOT 2
- Suppress a warning around SLF4J HOT 3
- Too many error messages and exceptions. HOT 1
- bug: Rename variable fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-language-server.