Skip to content
/ Mir Public

Mir speaks the LSP language and should help you build Sublime Text plugins with smart data

Notifications You must be signed in to change notification settings

Istok-Mir/Mir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simply, don't use it now:

  • Mir API will change without notice, the features that it exposes will change or be removed without notice, it is experimental not stable and not usable for most people (except for the one developer working on this).
  • Registering/unregistering capabilities is not implemented properly.
  • Windows and Linux is not tested and probably doesn't work.
  • It has some code that it should not have, for example ai.py.
  • language-server-*.py files should not be part of this repo.
  • the commit messages will most likely be gibberish 'asd' and will stay that way until things start to become serious.

Don't forget the LSP package for Sublime Text works. If you like something from Mir move it just to LSP.

The only thing that this code can give are ideas.

Mir

Mir is a Sublime Text package that speaks the LSP language but provides more on top of that.

What is Mir?

Mir collects data from "Langauge Servers" and from "Providers" pacakges.

# To read the data that Mir collected
completions = await mir.completions(self.view, point)
hovers = await mir.hover(self.view, hover_point)
definitions = await mir.definitions(self.view, point)

Example completion package implementation:

from __future__ import annotations
import sublime
import sublime_plugin
from .api import mir, run_future

class MirCompletionListener(sublime_plugin.ViewEventListener):
    def on_query_completions(self, _prefix: str, locations: list[Point]):
        completion_list = sublime.CompletionList()
        run_future(self.do_completions(completion_list, locations[0]))
        return completion_list

    async def do_completions(self, completion_list: sublime.CompletionList, point: int):
        completions_results = await mir.completions(self.view, point)
        completions: list[sublime.CompletionValue] = []
        for name, result in completions_results:
            if isinstance(result, dict):
                items = result['items']
                for i in items:
                    completions.append(sublime.CompletionItem(i['label']))
            elif isinstance(result, list):
                items = result
                for i in items:
                    completions.append(sublime.CompletionItem(i['label']))
        completion_list.set_completions(completions, sublime.INHIBIT_WORD_COMPLETIONS)

See Mir/package-implemenation-*.py files for examples.


Example of a language server for Mir:

from .api import LanguageServer

class PackageVersionServer(LanguageServer):
    name='package-version-server'
    cmd='/Users/predrag/Downloads/package-version-server'
    activation_events={
        'selector': 'source.json',
        'on_uri': ['file://**/package.json'],
    }

See Mir/package-language-server-*.py files for examples.


Language servers are not the only way to provide data to Mir. Provider packages can be written to enhance mir.

# this is just a concept
from .api.types import Hover, MarkupKind, Diagnostic
from .api import HoverProvider, mir
from .api.helpers import range_to_region
import sublime

class ExampleHoverProvider(HoverProvider):
    name= 'Package Json Enhancer'
    activation_events = {
        'selector': 'source.json',
        'on_uri': ['file://**/package.json'],
    }
    async def provide_hover(self, view: sublime.View, hover_point: int, hover_zone: sublime.HoverZone) -> Hover:
        if hover_point % 2 == 0:
            return {
            'contents': {
                'kind': MarkupKind.Markdown,
                'value': '\n'.join([
                    '# Header',
                    f'Some text {view.file_name()}',
                    '```typescript',
                    'someCode();',
                    '```',
                    'Or this:',
                    '```diff',
                    '- someCode();',
                    '+ someCodeAsd();',
                    '// some comment',
                    '```'
                 ])
            }
        }
        return {
          'contents': ['Hover Content']
        }

See Mir/package-provider-*.py files for examples.

About

Mir speaks the LSP language and should help you build Sublime Text plugins with smart data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages