Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register services in package.yaml instead via ServiceLoader #11868

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

JaroslavTulach
Copy link
Member

Pull Request Description

Designs a fix for #11724. package.yaml is extended with

- services
  - provides: SPI_Type_Name
    with: Implementation_Type_Name

and a new method lookup_services will read all such info and load the implementations just like demonstrated in MetaServicesTest.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

Copy link
Member Author

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radeusgd, @jdunkerley & others, can you please review this concept for service registration? If it is found sound, I provide proper implementation of the lookup_services builtin.

@@ -924,3 +919,16 @@ local_file_move (source : File) (destination : File) (replace_existing : Boolean
File_Error.handle_java_exceptions source <|
copy_options = if replace_existing then [StandardCopyOption.REPLACE_EXISTING.to_text] else []
source.move_builtin destination copy_options

# PRIVATE
type File_System_SPI
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First step, @radeusgd, is to define an SPI type. It can contain any information needed to process the registered instances. In this case it is protocol name. For purposes of simplicity the other argument is typ - to keep the implementation compatible, but one could do better, probably.

if vec . not_empty then vec.first else Nothing

private get_types _:Boolean =
Meta.lookup_services File_System_SPI
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To look the implementations up one will be allowed to use lookup_services method and specify the SPI type one is interested in. The behavior of the lookup_services method will be similar to the operations shown in the MetaServicesTest.

@@ -29,3 +29,7 @@ component-groups:
- Logical: { color: oklch(0.464 0.14 300) }
- Operators: { color: oklch(0.464 0.14 275) }
- Errors: { color: oklch(0.464 0.14 15) }

services:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To register an implementation one adds services section that specifies pair of SPI type and implementation type.

@jdunkerley: If you want the IDE to show a drop box with all available providers sooner than the library is loaded, then we might need (localized) display name explaining why such a library should be imported. Engine+ls would deliver list of all possible implementations to the IDE via suggestion db or etc.

Copy link
Member Author

@JaroslavTulach JaroslavTulach Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

James would like Meta.lookup_services to be able to return even the not enabled services. Then one can create a drop down with a selection of all possible implementation. Question: what happens when a not enabled service is selected? How does one turn that library on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall Meta provide something like Meta.is_library_imported? Then if not, we could give some feedback to the language server and ask it to insert a missing import.

Copy link
Member Author

@JaroslavTulach JaroslavTulach Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feedback to the language server

E.g. if we continue to insist on solving the problem with not enabled services we effectively put this PR on hold.

import project.System.File.File_System_SPI
import project.Enso_Cloud.Enso_File

type Enso_File_System_Impl
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration of implementation can be done in a private module by defining a singleton type (which is its own type) and a conversion from such type to the SPI interface. In this case the conversion is using File_System_SPI.new factory method.

@JaroslavTulach JaroslavTulach changed the title Register services in package.yaml instead via ServiceLoader Register services in package.yaml instead via ServiceLoader Dec 16, 2024
Copy link
Member

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to keep org.enso.base.file_system.FileSystemSPI? Why not migrate other service implementations in this PR as well?

* @param provides name of SPI type
* @param with name of implementation type
*/
case class ProvidesWith(val provides: String, val `with`: String) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change String to org.enso.pkg.QualifiedName?


type Enso_File_System_Impl

File_System_SPI.from (_:Enso_File_System_Impl) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure this works, you should remove EnsoPathFileSystemImpl.java?

JaroslavTulach and others added 2 commits December 17, 2024 08:09
Co-authored-by: Hubert Plociniczak <[email protected]>
Co-authored-by: Hubert Plociniczak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enso facility for finding implementations of SPI across loaded/available libraries
5 participants