Code Monkey home page Code Monkey logo

Comments (5)

rami3l avatar rami3l commented on May 18, 2024 2

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.

halarus avatar halarus commented on May 18, 2024 1
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.

fwcd avatar fwcd commented on May 18, 2024

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.

halarus avatar halarus commented on May 18, 2024

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.

themkat avatar themkat commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.