Custom Fleet Plugins for Your Kotlin Codebase | Vitaly Bragilevsky
Summary
TLDRVitali Brail from JetBrains introduces the concept of custom Fleet plugins for coding projects. Fleet, a multi-language code editor, offers built-in tools for remote development and collaboration. However, for specific needs like custom views or external tool integration, custom plugins are essential. Brail demonstrates creating a simple 'count functions' plugin, emphasizing the importance of understanding Fleet's database and structured concurrency. He highlights the ease of developing plugins with just 100 lines of code and encourages developers to look forward to the public preview of Fleet plugins.
Takeaways
- 😀 Vitali Brail from JetBrains is introducing custom Fleet plugins for coding bases.
- 🔍 Fleet is a multi-language code editor designed for remote development and collaboration.
- 🛠 Sometimes, out-of-the-box features aren't enough, and custom plugins are needed for specific tasks.
- 📚 Custom plugins can provide additional insights, like code base size or cyclomatic complexity.
- 💡 Creating a custom Fleet plugin involves writing code, running it in development, and publishing it on the marketplace.
- 🚧 Fleet plugins are a work in progress and not yet available to everyone, but a public preview is coming.
- 🌐 The architecture of Fleet centers around a workspace that manages projects and communicates with other components.
- 🔧 Plugins for Fleet involve implementing components for the front end, workspace, and backend (which is an IntelliJ IDEA plugin).
- 📝 The script provides a simple example of a 'count functions' plugin that updates a notification based on the number of functions in a code base.
- 🔑 Two key principles for coding with Fleet are using transactions for changes and embracing Kotlin's structured concurrency.
- 📈 The 'count functions' plugin is a concise example, implemented in under 100 lines of code, demonstrating the potential for more complex plugins.
Q & A
Who is Vitali Brailo, and what is his role at JetBrains?
-Vitali Brailo is a Developer Advocate at JetBrains, where he works with the Fleet team to make Fleet plugins a reality.
What is Fleet, and what is its primary purpose?
-Fleet is a code editor designed to support many programming languages simultaneously. It is aimed at providing a pleasant remote development experience and implementing collaboration scenarios.
Why might someone need to create a custom Fleet plugin?
-One might need a custom Fleet plugin for various reasons, such as using unique resources in their codebase, integrating with external tools not available out of the box, or obtaining additional information about their codebase like total size or cyclomatic complexity.
How easy is it to create a custom Fleet plugin according to the transcript?
-Creating a custom Fleet plugin is described as very easy. It involves writing code for the plugin, running Fleet with the plugin in development, and then publishing it on the marketplace for easy installation.
What is the current status of Fleet plugins according to the talk?
-As of the talk, Fleet plugins are a work in progress and are not yet available to everyone. The team is working towards making them available for public preview.
Can you explain the 'count functions' plugin example mentioned in the script?
-The 'count functions' plugin is a simple example that counts the number of top-level functions in a codebase. It updates a notification to reflect the current number of functions whenever changes are made to the code.
What are the two basic principles of coding when developing plugins for Fleet?
-The two principles are: 1) Fleet is a distributed database with reactive queries, where every change is made through transactions, and 2) Fleet embraces Kotlin's structured concurrency, requiring developers to be proficient in its use.
How does the 'count functions' plugin interact with the Fleet database?
-The plugin uses reactive queries to monitor changes in the abstract syntax tree of the file loaded into the editor. It performs a transaction to create and update a notification reflecting the current count of functions in the codebase.
What is the significance of the 'L' function in the context of the plugin?
-The 'L' function is crucial as it is executed when the plugin is loaded into Fleet. It is where all the functionality of the plugin, such as registering actions and notifications, is registered.
How does the plugin manage notifications and actions?
-The plugin registers a notification category and creates notifications within a transaction block. Actions are defined using a DSL (Domain-Specific Language) in Fleet, which specifies conditions for the action's availability and the function to execute when the action is triggered.
What is the role of structured concurrency in the plugin's coroutine execution?
-Structured concurrency ensures that every coroutine is executed within a specific scope. If the plugin is unloaded, all coroutines within that scope are automatically cancelled, providing control over the plugin's functionality.
Outlines
😀 Introduction to Custom Fleet Plugins
Vitali Brailo, a Developer Advocate at JetBrains, introduces the concept of custom Fleet plugins. Fleet is a versatile code editor designed for multiple programming languages, with a focus on remote development and collaboration. Although Fleet offers built-in support for languages like C and Kotlin, as well as tools like Amper for project building, there are instances where developers might require custom functionality. This could include custom views for unique resources, integration with external tools, or additional insights into the codebase such as cyclomatic complexity. Vitali explains that creating a custom Fleet plugin is straightforward, involving writing code, testing it in development mode, and then publishing it on the marketplace for easy installation. However, he notes that Fleet plugins are a work in progress and not yet available to everyone, but the team is working towards a public preview.
🛠️ Building a Simple 'Function Counter' Plugin
The speaker proceeds to demonstrate the process of creating a simple plugin for Fleet, using the 'Function Counter' as an example. He outlines the basic principles of coding for Fleet, emphasizing its nature as a distributed database with reactive queries and the importance of structured concurrency. The 'Function Counter' plugin, which counts the number of top-level functions in a Kotlin source file, is explained in detail. The plugin class is simple, with the main functionality registered in the 'load' function, including the creation and management of notifications and actions. The speaker describes how to create and update notifications within a transactional database context and how to define actions using a DSL (Domain-Specific Language) in Fleet. The core functionality involves querying changes in the abstract syntax tree of the file and updating the notification accordingly, showcasing the plugin's ability to interact with the Fleet database and editor.
🔍 Deep Dive into Plugin Implementation and Future Outlook
In the final paragraph, the speaker delves deeper into the implementation details of the 'Function Counter' plugin, highlighting the simplicity of the code, which consists of less than 100 lines. He explains the use of transactions for database changes and the structured concurrency approach that Fleet employs to manage plugin functionality. The speaker also discusses the reactive query mechanism that allows the plugin to respond to changes in the code, such as counting functions and updating the UI in real-time. The 'Count Functions' function is described as a straightforward interaction with the abstract syntax tree of the file loaded into the editor. The speaker concludes by expressing the team's ongoing efforts to make Fleet plugins publicly available, inviting users to look forward to the public preview and encouraging them to vote for the feature, adding a humorous note about the potential consequences of not receiving enough votes.
Mindmap
Keywords
💡Fleet
💡Developer Advocate
💡Custom Fleet plugins
💡Remote development
💡Collaboration scenarios
💡Codlin
💡Structured concurrency
💡Reactive queries
💡Abstract syntax tree (AST)
💡Plugin marketplace
💡IntelliJ IDEA plugin
Highlights
Vitali Brailo, a developer advocate at JetBrains, discusses the creation of custom Fleet plugins for coding code bases.
Fleet is a multi-programming language code editor designed for remote development and collaboration.
Fleet comes with built-in support for languages like C and Kotlin, and tools like Amper for project building.
Custom plugins are needed for unique requirements such as custom views, external tool integration, and additional code base insights.
Creating a custom Fleet plugin involves writing code, running it in development mode, and publishing it to the marketplace.
Fleet plugins are currently a work in progress and not yet available to everyone.
A simple plugin example called 'count functions' dynamically updates the number of functions in a code base.
Fleet's architecture centers around a workspace that manages projects and interacts with various components.
Fleet's front end communicates with users, while the backend, such as IntelliJ's, handles heavy tasks like indexing and static analysis.
Plugin development for Fleet requires implementing components for the front end, workspace, and sometimes the backend.
Two fundamental principles of coding for Fleet include its distributed database nature and embracing Kotlin's structured concurrency.
The 'count functions' plugin is a concise example, implemented in under 100 lines of code.
The plugin class in Fleet is basic and may not provide an API, focusing instead on functionality registration.
Notifications in Fleet are managed through categories and editor entities, with updates handled via transactions.
Actions in Fleet are defined using a DSL, requiring an editor and reacting to changes in the code base.
Structured concurrency is utilized to manage plugin functionality, ensuring coroutines are cancelled when a plugin is unloaded.
The core of the 'count functions' plugin involves querying the abstract syntax tree for changes and updating notifications accordingly.
JetBrains aims to make Fleet plugin development open to everyone once the public preview is ready.
The talk concludes with an invitation for attendees to vote for the plugin feature, emphasizing its upcoming availability.
Transcripts
[Music]
so hi hi folks hi hi everyone I am
Vitali brail I work at jet brains as a
developer Advocate and I work with the
fleet team to to make Fleet plugins
actually happening so uh today I'm going
to talk about Custom Fleet plugins for
your codling code base so just to start
uh Fleet is a code editor for many many
programming languages at the same time
and uh it was designed to make nice to
have nice remote development to have to
implement nice collaboration scenarios
things like that and chances are that
you already have your code base in C in
cotlin and you manage them with a fleet
and in Fleet we also have codlin
multiplatform we also have Amper to
build your projects maybe and then all
this stuff is already there it is
available out of the
box but sometimes you need something
else you need something
custom and it can this can be different
things like for example you use your own
resources in your code base and you need
custom views sometimes you want to
integrate with with external tools which
are not available out of the box
sometimes you want to get some
additional information about your code
base for example What's the total size
or something like cyclomatic complexity
if you don't know what it is just in
Wikipedia they tell you everything about
that or AI or something abstraction
complexity so sometimes you want to see
if your comments are actually relevant
to the code so something custom which is
not available and at this very point
point you might need to write a Custom
Fleet plugin and in fact it's very easy
to do you just create a rapper for uh
the plug-in you write your code then you
write Fleet you can run Fleet with a
plugin in development and then you
publish it on the marketplace and then
everyone can install it just with single
click from Fleet itself of course it's
something like that like if you're
drawing a o but uh I should say one
thing here so Fleet plugins are work in
progress at this type so they're not
available for everyone but we're working
towards making them available we're
going towards our public uh preview for
plugin so just uh uh in this talk I will
show you something how you are supposed
to do things like that and I will use
one very simple example of a plug-in for
Fleet so let me show it to you so I have
Fleet I have some codlin project here
and I have two functions you can see
them and I have
this action which was designed in this
plugin which is called count functions
and it shows this small uh notification
here and it says that you have two
functions in this code base in this file
and let me for example add another
function with this name and at this very
the moment you can see that it was
changed to three so you have two
functions and then immediately you have
three functions three top level
functions in this code base so very
simple plug-in and that's exactly what
I'm going to present in this
talk so Fleet is a product with very
interesting very modern architecture
workspace is in the center of Fleet it
manages your project and it knows
everything about any other component
which is connected to it we also have
one or many front end components
responsible for actually communicating
with the user like views some actions
you edit your code with front ends there
is syntax highlighting implementing
there and then there is also backend
part which in case of cotland is
intellig backend which is a headless
service from intell idea basically and
it does heavy lifting like indexing
static analysis Advanced code navigation
stuff like that and if you develop
plugins for Fleet you basically
Implement some components for the front
end part for the workspace part and also
for the bend part now beend part is
basically an intell J idea plugin so
we're not talking about it here because
it works right there on back end but
workspace part and front end part they
are just parts of app PL in and they
become parts of lead itself and my count
functions plugin actually works only on
the front end part so it's called Fun
counter and let's see how we can
Implement something like
that
uh before starting writing code for
Fleet we have to remember two basic
principles of that coding principle
number one Fleet is actually a
distributed database with reactor qu
queries every change that you are doing
goes in a transaction so you write
transactions to change everything in
Fleet and you also have reactive queries
so that you can uh quer make a query for
something and then you get notifications
about changes in that database and
principle number two Fleet Embraces
cortin structured concurrency scoped
concurrency everything that you like in
cotland it's there in Fleet so you have
to be like professional in that stuff to
develop plugins for Fleet okay um very
uh like this this plugin that I showed
you it's uh in 100 lines of code just
single file we have uh special class for
a plug-in and then several functions for
managing notifications for actually
counting functions so let's see what's
inside that
implementation so plug-in class is just
a basic class very small one and in
general plugins can Implement some API
and in fact real Fleet code base is
already it has a lot of plugins there
and some of them provide some API for
this plugin it's not needed so it's just
unit my API is just unit nothing
interesting so we don't provide anything
we just do some other stuff then we also
have some book keeping arguments here
values it's for loading and unloading
plugins it's for Fleet itself so this
class basically is loaded using service
loader like as usual in in Java uh gvm
so this is for for that stuff and now
the most important part of this
definition is the L function L function
is executed when you actually lowed your
plugin in Fleet so every piece of
functionality is registered here this
low function so for example in this
particular example we have a
notification so we register category for
it and we also have an action count
functions action so these two things are
right here in this uh low out function
right uh it's very simple to manage
notifications so we have a category so
we register it so we say like there may
be like several files and chance say are
we have several notifications at the
same time so we need a category for them
so we register it and we also create
notification and then we should think
about updating it so creating
notification is very easy so you create
it from an editor and you see that
argument there editor entity above on
the first line so entity it's just some
component from database basically so you
have an editor you create a notification
for that specific editor then you
consult Editor to just get name of the
file which is loaded into that editor so
you describe all that stuff and now the
most important uh part here
change this change block is actually a
transaction so in cotland we Define a
transaction and in that transaction we
create that
notification and we also do some
bookkeeping in with this database for
example with Cascade delete call there
we just say Okay this notification
depends on that editor if editor is
deleted then this notification should be
deleted as well so it's real database
and change block is a transaction there
so this function returns a notification
and then if you want to update the
notification you need to issue another
transaction so you see change block here
again so you change
description and that means that it will
be changed in the database and it will
also be updated in the UI of course but
uh so that's an idea Fleet is a database
and you change everything in that
database with
transactions now action the most
important part here we have uh DSL for
defining actions in Fleet so this is an
example of it so it's an AC ction and we
say that for this action we need an
editor if there is no editor in Fleet
then it's impossible to have this action
because we it it's uh too tightly
connected with it so we require an
editor then we say so if there is no
editor then there will be no that action
in the actions list then we say it's a
dynamic actions meaning that if that
editor contains a file which is not
cotlin Source then we are not
interested this action will be disabled
so if it's a cotlin source we say it
right there Then in that case we
Define a function which will be executed
whenever this action is
triggered and what is actually we're
doing when it's triggered we launch a
core routine and we launch it in the
so-called plug-in scope do you see that
plug-in scope argument that's piece of
structured concurrency stuff so every
cortin is executed inside that scope so
Fleet knows when it loads this plugin it
knows that scope so if it decided to
unload that plug-in then every coroutine
will be cancelled on this time so we
control every uh piece of functionality
using structured concurrency here so we
launch that coroutine and we actually
perform that action now remember what is
in that action so I change some code in
file and then this change should be
propagated to the
notification so change here change there
so we need to describe this somehow and
this is actually the core part of this
plugin so this function works with with
an editor and if you see that with
entities there so that means that it
will be cancelled if there is no editor
anymore automatically for us now we
create notification using the function
that we saw earlier and we'll say we do
that while the notification is alive
when it's deleted from the database then
once again this Corin is going to be
cancelled okay and now the central part
of that Fleet database remember that
stuff about reactive queries so we say
basically here query for every change in
abstract syntax Tre of the file loaded
of the document loaded into that
editor so for every change we get an
asynchronous
flow and we need to do some processing
with that flow so query we say what we
are interested in and then in the second
part in colle
latest so we are collecting elements
from the flow we count functions in the
particular abstract syntax tree from
that editor and then we update a
notification so basic idea we have a
query reactive database and we have
collecting latest values sometimes we
can skip some changes that's fine
because we always have an access to the
latest stuff right there
and the final piece of code here is
Count functions function so it's
basically very simple exercise in uh
communicating with the abstract syntax
tree so syntax of that file that is
loaded into the editor so we're going to
the root look at the Children's and
we're interested in top level functions
only so that's why that's enough for me
so no much too much navigation over over
there and then that's it so below 100
lines of code we've implemented this uh
staff for Fleet and of course it takes
much more lines of course to implement
something much more meaningful much more
sophisticated but it's still possible or
will be possible for everyone whenever
we are ready with our Fleet plugins
public preview so the goal of this stock
was to make you aware of that stuff so
we are working on it and we will make it
open very soon so that everyone can try
to implement their own plugins for Fleet
okay and uh thank you very much and
please don't forget to vote if you like
it otherwise I'll be
fired thank you very much folks thanks
for coming
[Music]
Ver Más Videos Relacionados
Penjelasan Lengkap Tentang Wordpress : Fitur, Keunggulan Dan Fungsinya | Upskilling With SUHU
Introduction to Plugin Architecture in C#
🏆️ TOP 10 BEST Obsidian Plugins 🔌️
7 Wordpress Plugins I install on all websites (2024)
AI and Kotlin: A Perfect Mix | Vladislav Tankov
Creating typography system in Figma
5.0 / 5 (0 votes)