Skip to content

Commit

Permalink
Clearing code and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
kizeevov committed Mar 19, 2024
1 parent 64395a2 commit 5c47e08
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 128 deletions.
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
## Description

<!-- Plugin description -->
[Slint](https://slint.dev) support for IDEs based on IntelliJ Platform. **Plugin is experimental and unofficial!**
[Slint](https://slint.dev) support for IDEs based on IntelliJ Platform. **Plugin is unofficial!**

The following features are supported:
- Syntax highlighting
- Slint-LSP support
- Preview support
- Code completion
- Document formatting
- Pick elements
- Drag and Drop elements on Live-Preview
<!-- Plugin description end -->

Tested with:
- CLion 2023.2
- IDEA Ultimate 2023.2
- RustRover 2023.3 EAP

## Dependencies

Slint IntelliJ Plugin communicates with Slint-LSP. Install before you can use the IntelliJ Plugin. To install:
```sh
$ cargo install slint-lsp
```
Slint IntelliJ Plugin communicates with Slint LSP. Language server are included in plugin assembly (in version 1.0.0 and later).

But you can use an external dependency. Go to <kbd>Settings</kbd> > <kbd>Languages & Frameworks</kbd> > <kbd>Slint</kbd> > <kbd>Slint-lsp path</kbd> selected path

## Installation

Expand All @@ -38,7 +35,3 @@ Manually:

Download the [latest release](https://github.com/kizeevov/slint-idea-plugin/releases) and install it manually using
<kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>

## Configuration

Go to <kbd>Settings</kbd> > <kbd>Languages & Frameworks</kbd> > <kbd>Slint</kbd> > <kbd>Slint-lsp path</kbd> selected path
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pluginRepositoryUrl = https://github.com/kizeevov/slint-idea-plugin

pluginGroup = dev.slint
pluginName = SlintPlugin
pluginVersion = 0.3.1
pluginVersion = 1.0.0
platformType = IU
# platformType = CL
platformVersion = 232-EAP-SNAPSHOT
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/dev/slint/ideaplugin/SlintBundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ object SlintBundle : DynamicBundle(SLINT_BUNDLE) {
@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = SLINT_BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)
getMessage(key, *params)

@Suppress("SpreadOperator", "unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = SLINT_BUNDLE) key: String, vararg params: Any) =
getLazyMessage(key, *params)
getLazyMessage(key, *params)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.platform.lsp.api.LspServer
import dev.slint.ideaplugin.ide.services.SlintServerService
import javax.swing.Icon


abstract class LspAction(text: String, description: String?, icon: Icon?) : AnAction(text, description, icon) {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
Expand All @@ -16,6 +15,7 @@ abstract class LspAction(text: String, description: String?, icon: Icon?) : AnAc
if (servers.isEmpty()) {
return
}

actionPerformed(e, servers)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import dev.slint.ideaplugin.lang.SlintLanguage
import kotlin.io.path.Path

internal class PreviewAction(private val notification: Notification? = null) :
LspAction("Show All Preview", null, AllIcons.Actions.Preview)
{
LspAction("Show All Preview", null, AllIcons.Actions.Preview) {
override fun update(e: AnActionEvent) {
val psiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return
e.presentation.isEnabledAndVisible = psiFile.language.isKindOf(SlintLanguage.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import dev.slint.ideaplugin.ide.lsp.requests.PreviewMessageRequest
import kotlin.io.path.Path

internal class PreviewComponentAction(
private val componentName: String,
private val notification: Notification? = null,
private val componentName: String,
private val notification: Notification? = null,
) :
LspAction("Show Component Preview", null, AllIcons.Actions.ShowCode)
{
LspAction("Show Component Preview", null, AllIcons.Actions.ShowCode) {
override fun actionPerformed(e: AnActionEvent, servers: List<LspServer>) {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return
val uriFile = Path(virtualFile.path).toUri()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import com.intellij.ide.actions.CreateFileFromTemplateAction
import com.intellij.ide.actions.CreateFileFromTemplateDialog
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.client.currentSession
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.psi.PsiDirectory
import dev.slint.ideaplugin.SlintBundle
import dev.slint.ideaplugin.SlintIcons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,35 @@ package dev.slint.ideaplugin.ide.annotator
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey
import com.intellij.psi.PsiElement
import com.intellij.psi.util.elementType
import dev.slint.ideaplugin.ide.highlighting.SlintColors
import dev.slint.ideaplugin.lang.psi.SlintElementTypes


class SlintAnnotator : Annotator {
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
if (element.elementType == SlintElementTypes.FIELD_IDENTIFIER)
{
if (element.elementType == SlintElementTypes.FIELD_IDENTIFIER) {
annotateWithInfo(element, holder, SlintColors.FIELD_NAME)
} else if (element.elementType == SlintElementTypes.DURATION_LITERAL
|| element.elementType == SlintElementTypes.LENGTH_LITERAL
|| element.elementType == SlintElementTypes.PHYSICAL_LENGTH_LITERAL
|| element.elementType == SlintElementTypes.ANGLE_LITERAL
|| element.elementType == SlintElementTypes.COLOR_LITERAL
|| element.elementType == SlintElementTypes.RELATIVE_FONT_SIZE_LITERAL)
{
|| element.elementType == SlintElementTypes.RELATIVE_FONT_SIZE_LITERAL
) {
annotateWithInfo(element, holder, SlintColors.NUMBER)
}
}

private fun annotateWithInfo(
element: PsiElement,
holder: AnnotationHolder,
attributesKey: TextAttributesKey
element: PsiElement,
holder: AnnotationHolder,
attributesKey: TextAttributesKey
) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(element.textRange)
.textAttributes(attributesKey)
.create()
.range(element.textRange)
.textAttributes(attributesKey)
.create()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.tree.IElementType
import dev.slint.ideaplugin.lang.psi.SlintElementTypes

class SlintBraceMatcher: PairedBraceMatcher {
class SlintBraceMatcher : PairedBraceMatcher {
override fun getPairs(): Array<BracePair> = braces

override fun isPairedBracesAllowedBeforeType(lbraceType: IElementType, contextType: IElementType?): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package dev.slint.ideaplugin.ide.editor
import com.intellij.codeInsight.editorActions.SimpleTokenSetQuoteHandler
import dev.slint.ideaplugin.lang.psi.SLINT_STRINGS

class SlintQuoteHandler: SimpleTokenSetQuoteHandler(SLINT_STRINGS)
class SlintQuoteHandler : SimpleTokenSetQuoteHandler(SLINT_STRINGS)
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ private fun PsiElement.nextImport(): SlintImportDefinition? {
return next.nextImport()
}

return next as? SlintImportDefinition
return next as? SlintImportDefinition
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.intellij.formatting.service.FormattingService
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.service
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.progress.util.ProgressIndicatorBase
import com.intellij.psi.PsiFile
import com.jetbrains.rd.util.enumSetOf
import dev.slint.ideaplugin.ide.services.FileEditorService
Expand All @@ -17,7 +16,7 @@ import org.eclipse.lsp4j.FormattingOptions
import org.eclipse.lsp4j.TextDocumentIdentifier
import kotlin.io.path.Path

class SlintLspFormattingService: AsyncDocumentFormattingService() {
class SlintLspFormattingService : AsyncDocumentFormattingService() {
override fun getFeatures(): Set<FormattingService.Feature> = FEATURES

override fun canFormat(file: PsiFile): Boolean = file is SlintFile
Expand All @@ -40,7 +39,7 @@ class SlintLspFormattingService: AsyncDocumentFormattingService() {

return object : FormattingTask {
override fun run() {
val edits = server.lsp4jServer.textDocumentService.formatting(params).join()
val edits = server.lsp4jServer.textDocumentService.formatting(params).join()
edits.forEach { textEdit ->
WriteCommandAction.runWriteCommandAction(project) {
FileEditorService.applyTextChanges(textEdit, editor)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SlintSyntaxHighlighter : SyntaxHighlighterBase() {
override fun getHighlightingLexer(): Lexer = SlintLexer()

override fun getTokenHighlights(tokenType: IElementType): Array<TextAttributesKey> =
pack(attributes[tokenType])
pack(attributes[tokenType])

companion object {
private val attributes = buildMap<IElementType, TextAttributesKey> {
Expand Down
10 changes: 0 additions & 10 deletions src/main/kotlin/dev/slint/ideaplugin/ide/lsp/LspLanguageClient.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package dev.slint.ideaplugin.ide.lsp

import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.project.Project
import com.intellij.platform.lsp.api.Lsp4jClient
import com.intellij.platform.lsp.api.LspServerNotificationsHandler
import dev.slint.ideaplugin.ide.services.FileEditorService
import dev.slint.ideaplugin.ide.services.SlintServerService
import org.eclipse.lsp4j.*
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
import java.util.concurrent.CompletableFuture
Expand All @@ -31,8 +25,6 @@ class LspServerNotificationsMiddleware(

override fun applyEdit(params: ApplyWorkspaceEditParams): CompletableFuture<ApplyWorkspaceEditResponse> {
fileEditorService.applyEdit(params)

// return serverNotificationsHandler.applyEdit(params)
return CompletableFuture.supplyAsync {
null
}
Expand Down Expand Up @@ -88,8 +80,6 @@ class LspServerNotificationsMiddleware(

override fun showDocument(params: ShowDocumentParams): CompletableFuture<ShowDocumentResult> {
fileEditorService.showDocument(params)

// return serverNotificationsHandler.showDocument(params)
return CompletableFuture.supplyAsync {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.eclipse.lsp4j.CompletionItemKind
import javax.swing.Icon

@Suppress("UnstableApiUsage")
class SlintLspCompletionSupport: LspCompletionSupport() {
class SlintLspCompletionSupport : LspCompletionSupport() {
override fun getIcon(item: CompletionItem): Icon {
return super.getIcon(item) ?: SlintIcons.SLINT
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,16 @@ package dev.slint.ideaplugin.ide.lsp

import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.process.ProcessAdapter
import com.intellij.execution.process.ProcessEvent
import com.intellij.ide.plugins.PluginManager
import com.intellij.openapi.components.service
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.Lsp4jClient
import com.intellij.platform.lsp.api.LspServerListener
import com.intellij.platform.lsp.api.LspServerNotificationsHandler
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import com.intellij.platform.lsp.api.customization.LspCompletionSupport
import dev.slint.ideaplugin.ide.settings.SlintBackend
import dev.slint.ideaplugin.ide.settings.SlintSettingsState
import dev.slint.ideaplugin.ide.settings.SlintStyle
import dev.slint.ideaplugin.lang.SlintFileType
import org.eclipse.lsp4j.services.LanguageServer
import com.intellij.openapi.util.SystemInfo
import dev.slint.ideaplugin.SlintBundle
import dev.slint.ideaplugin.ide.services.SlintServerService
import java.nio.file.Path
import java.util.*
import kotlin.concurrent.schedule

@Suppress("UnstableApiUsage")
class SlintLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Slint") {
Expand All @@ -35,9 +22,11 @@ class SlintLspServerDescriptor(project: Project) : ProjectWideLspServerDescripto

override fun createInitializationOptions(): Any = SlintSettingsState.getInstance().lspSettings

override fun createLsp4jClient(handler: LspServerNotificationsHandler): Lsp4jClient = LspLanguageClient(handler, project)
override fun createLsp4jClient(handler: LspServerNotificationsHandler): Lsp4jClient =
LspLanguageClient(handler, project)

override fun startServerProcess(): OSProcessHandler = ServerProcessHandler.addListeners(super.startServerProcess(), project)
override fun startServerProcess(): OSProcessHandler =
ServerProcessHandler.addListeners(super.startServerProcess(), project)

override val lsp4jServerClass: Class<out LanguageServer> = SlintLanguageServer::class.java
override val lspServerListener: LspServerListener = SlintLspServerListener(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import dev.slint.ideaplugin.lang.SlintFileType

@Suppress("UnstableApiUsage")
class SlintLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) {
override fun fileOpened(
project: Project,
file: VirtualFile,
serverStarter: LspServerSupportProvider.LspServerStarter
) {
if (file.fileType != SlintFileType) return
serverStarter.ensureServerStarted(SlintLspServerDescriptor(project))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import com.intellij.platform.lsp.api.requests.LspRequest
import org.eclipse.lsp4j.ExecuteCommandParams
import java.util.concurrent.CompletableFuture

class PreviewMessageRequest(private val server: LspServer, private val path: String, private val component: String) : LspRequest<Any, Any>(server) {
class PreviewMessageRequest(private val server: LspServer, private val path: String, private val component: String) :
LspRequest<Any, Any>(server) {
override fun preprocessResponse(serverResponse: Any): Any {
return serverResponse
}

override fun sendRequest(): CompletableFuture<Any> {
return server.lsp4jServer.workspaceService
.executeCommand(
ExecuteCommandParams(
"slint/showPreview",
listOf(path, component)
)
.executeCommand(
ExecuteCommandParams(
"slint/showPreview",
listOf(path, component)
)
)
}
}
Loading

0 comments on commit 5c47e08

Please sign in to comment.