Code Monkey home page Code Monkey logo

kobweb-intellij-plugin's People

Contributors

bitspittle avatar dennistsar avatar nxllpointer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

nxllpointer

kobweb-intellij-plugin's Issues

Show actions for handling a `private val ComponentStyle/ComponentVariant/Keyframes`

See the important note in this section: https://github.com/varabyte/kobweb?tab=readme-ov-file#componentstyle

In other words, detect this case:

private val SomeStyle by ComponenStyle

then put a warning on the "private" keyword and add two actions the user can take

  1. Remove the "private" modifier
  2. Introduce an initSilk method (or add to the end of an existing one if already defined)
@Suppress("PRIVATE_COMPONENT_STYLE")
private val SomeCustomStyle by ComponentStyle { /* ... */ }

@InitSilk
fun registerPrivateStyle(ctx: InitSilkContext) {
  ctx.theme.registerComponentStyle(SomeCustomStyle)
}

Proper icon

The plugin currently still uses the default template icon

Support setting the gutter color of a Kobweb color for Color.rgb / Color.hsl calls

For example, if you have something like this:

Kobweb color gutter

and you click on the red square, it brings up a color picker. Right now, we're ignoring the request to update the color if the user picks one.

The code to handle this would go in KobwebColorProvider::setColorTo, which is currently stubbed.

We're not always in a situation where we can change the color, but we might try to update things when we can. It could be pretty cool to write val x = Color.rgb(0, 0, 0) and then use the color picker to figure out the correct value we want.

We should support all the Kobweb color functions, specifically here: https://github.com/varabyte/kobweb/blob/14e9ccffb889907cb3ee9d94a0c3e90c3d33db74/frontend/kobweb-compose/src/jsMain/kotlin/com/varabyte/kobweb/compose/ui/graphics/Color.kt#L221

See also: https://github.com/JetBrains/intellij-community/blob/master/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaColorProvider.java

Add live templates for Kobweb

Live templates autocomplete code AND, if relevant, prompt users to fill out variable names before the completion is considered done.

We'll use VAR to represent things that should be filled out by the user and "$" to represent the cursor position when done.

For now we'll collect everything here because there probably aren't that many Kobweb concepts but we could break this up into multiple bugs if that's better.

Actual live template shortcut names are open for debate!

Frontend

cost/componentstyle = ComponentStyle

val VAR by ComponentStyle {
   base { Modifier.$ }
}

costb/componentstylebase = ComponentStyle.base

val VAR by ComponentStyle.base {
   Modifier.$
}

page

@Page
@Composable
fun VAR() {
   $
}

worker

val worker = rememberWorker {
   VAR { output ->
      $
   }
}

initsilk

@InitSilk
fun VAR(ctx: InitSilkContext) {
   $
}

initkobweb

@InitKobweb
fun VAR(ctx: InitKobwebContext) {
   $
}

Backend

api

@Api
fun VAR(ctx: ApiContext) {
   $
}

initapi

@InitApi
fun VAR(ctx: InitApiContext) {
   $
}

objapistream

val VAR = object : ApiStream {
   override suspend fun onTextReceived(ctx: TextReceivedContext) {
      $
   }
}

apistream

val VAR = ApiStream { ctx ->
   $
}

Warn if ComponentStyle is missing `base`

A common mistake, especially for beginners but not necessarily:

val SomeStyle by ComponentStyle {
   Modifier.size(...)
}

This compiles but does nothing. It should be:

val SomeStyle by ComponentStyle {
   base { Modifier.size(...) }
}

or

val SomeStyle by ComponentStyle.base {
   Modifier.size(...)
}

Add a warning if a route override isn't necessary

// pages/SomeSlug.kt

@Page("some-slug") 

☝️ Should be @Page


// pages/someRoute

@file:PackageMapping("some-route")

☝️ File should be deleted.


// pages/SomeSlug.kt

@Page("{some-slug}")

☝️ Should be @Page("{}")


// pages/someRoute

@file:PackageMapping("{some-route}")

☝️ Should be @file:PackageMapping("{}")

Easy linking to mozilla docs, e.g. when looking at quick docs for Kobweb modifiers

This will require a bunch of tagging in Kobweb with links to the source mozilla sites, but it might be nice to open a playground within your IDE to those CSS properties.

/**
 * ...
 * @see <a href="https://mozilla.com/...">...</a>
 */
fun Modifier.font(...)

results in an action which opens a floating web page inside your IDE that goes to the linked mozilla page. (Basically, search every header doc for each function call and search for a mozilla link in there)

We could support opening the page both with a quick action but ALSO with a gutter action too. That could be a really nice experience for bridging Kotlin and CSS.

Add a panel for surfacing information related to a widget

The driving idea here is, if I have my cursor on a Silk Button, can I quickly surface all relevant styles, variants, and stylevars? (Basically, the plugin would need to analyze its code and find all nested symbols which are one of those things, which it can share in a popup somewhere, probably in the quickdoc window)

Widget creator

A sidebar tool which shows all Silk widgets, and clicking on one will let users create code where the cursor is.

Caution

This sounds very difficult and we may not want to prioritize early on.

Only run Kobweb actions if we're in a proper Kobweb module

Probably some way to ask the current file context something like this:

enum class KobwebModuleType {
   APPLICATION,
   LIBRARY,
   WORKER;
}

// WORKER modules don't have access to the UI so many Kobweb actions / inspections are not relevant there
fun KobwebModuleType.isFramework() = this == APPLICATION || this == LIBRARY

fun Module.findKobwebType(): KobwebModuleType() = { /* how do we do this? */ }

// Later, say in UnusedInspectionSuppressor
someContext.module.findKobwebType()?.isFramework() ?: return // Early abort

Refactor inline styles into component styles

// Before
Widget(Modifier.styleA().styleB().styleC().attrA())

// After
val SomeStyle by ComponentStyle.base(extraModifiers = { Modifier.attrA() }) {
   Modifer.styleA().styleB().styleC()
}

Widget(SomeStyle.toModifier())

Refactor `ComponentStyle.base` approach

An action to convert between this:

val SomeStyle by ComponentStyle {
   base { Modifier.size(...) }
}

and this:

val SomeStyle by ComponentStyle.base {
   Modifier.size(...)
}

The action would show up if you put your cursor on the "base" word and hit alt-enter.

Note that the context action should NOT show up for this case:

val SomeStyle by ComponentStyle {
   base { Modifier.size(...) }
   hover { Modifier.whatever() }
}

Warn about Kobweb / Compose version mismatch

Can we discover those versions from the project's Gradle model? Worst case, we can parse libs.versions.toml directly, but that's more fragile. What if a user isn't using version catalogs?

Add tests

It is important to figure this out soon, so that new code that goes in will see a precedent that they should be using tests.

Warn if user is using an attribute Modifier inside a ComponentStyle

Warn if a user is using an attribute modifer within a component style (and offer assistance to extract it to the extraModifiers parameter)

// Before
val SomeStyle by ComponentStyle.base {
   Modifier.id("id").size(...)
            ^^
            "id" is an attribute modifier and not valid inside a ComponentStyle, which can only reference style modifiers
}

// After refactoring
val SomeStyle by ComponentStyle.base(extraModifiers = { Modifier.id("id") }) {
   Modifier.size(...)
}

Also support alt base syntax:

// Before
val SomeStyle by ComponentStyle {
   base { Modifier.id("id") }
}

// After refactoring
val SomeStyle by ComponentStyle(extraModifiers = { Modifier.id("id") }) {
   base { Modifier.size(...) }
}

For attribute modifiers that AREN'T in the base block, do NOT offer to refactor. Just show the warning.

val SomeStyle by ComponentStyle {
   hover { Modifier.id("id").size(...) }
                    ^^
}

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.