From dec93133620e088addd168ec104e9f251bc32ef4 Mon Sep 17 00:00:00 2001 From: Drew Malzahn Date: Sun, 5 Jul 2026 23:22:38 -0400 Subject: [PATCH] Initial commit --- .python-version | 1 + CLAUDE.md | 1 + LSP-prolog.sublime-commands | 10 ++++++++++ LSP-prolog.sublime-settings | 15 +++++++++++++++ Main.sublime-menu | 34 ++++++++++++++++++++++++++++++++++ README.md | 30 ++++++++++++++++++++++++++++++ boot.py | 18 ++++++++++++++++++ plugin/__init__.py | 20 ++++++++++++++++++++ plugin/plugin.py | 32 ++++++++++++++++++++++++++++++++ 9 files changed, 161 insertions(+) create mode 100644 .python-version create mode 100644 CLAUDE.md create mode 100644 LSP-prolog.sublime-commands create mode 100644 LSP-prolog.sublime-settings create mode 100644 Main.sublime-menu create mode 100644 README.md create mode 100644 boot.py create mode 100644 plugin/__init__.py create mode 100644 plugin/plugin.py diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..cc1923a --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8 diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..876724a --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +LSP-prolog implements a Sublime Text package providing support for a Prolog LSP, based off of Scryer Prolog. diff --git a/LSP-prolog.sublime-commands b/LSP-prolog.sublime-commands new file mode 100644 index 0000000..1832875 --- /dev/null +++ b/LSP-prolog.sublime-commands @@ -0,0 +1,10 @@ +[ + { + "caption": "Preferences: LSP-prolog Settings", + "command": "edit_settings", + "args": { + "base_file": "${packages}/LSP-prolog/LSP-prolog.sublime-settings", + "default": "// Settings in here override those in \"LSP-prolog/LSP-prolog.sublime-settings\"\n\n{\n\t$0\n}\n" + } + } +] diff --git a/LSP-prolog.sublime-settings b/LSP-prolog.sublime-settings new file mode 100644 index 0000000..1c953c4 --- /dev/null +++ b/LSP-prolog.sublime-settings @@ -0,0 +1,15 @@ +{ + // The command used to start the Prolog language server. This requires a + // build of scryer-prolog (https://github.com/mthom/scryer-prolog) whose + // "--lsp" flag runs a built-in LSP server communicating over stdio. + // If scryer-prolog is not on your PATH, change this to the absolute path + // of the binary. + "enable": true, + "command": [ + "scryer-prolog", + "--lsp" + ], + // Which files this language server should be used for. + "selector": "source.prolog", + "settings": {} +} diff --git a/Main.sublime-menu b/Main.sublime-menu new file mode 100644 index 0000000..97f085e --- /dev/null +++ b/Main.sublime-menu @@ -0,0 +1,34 @@ +[ + { + "id": "preferences", + "children": [ + { + "caption": "Package Settings", + "mnemonic": "P", + "id": "package-settings", + "children": [ + { + "caption": "LSP", + "id": "lsp-settings", + "children": [ + { + "caption": "Servers", + "id": "lsp-servers", + "children": [ + { + "caption": "LSP-prolog", + "command": "edit_settings", + "args": { + "base_file": "${packages}/LSP-prolog/LSP-prolog.sublime-settings", + "default": "// Settings in here override those in \"LSP-prolog/LSP-prolog.sublime-settings\"\n\n{\n\t$0\n}\n" + } + } + ] + } + ] + } + ] + } + ] + } +] diff --git a/README.md b/README.md new file mode 100644 index 0000000..3317658 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# LSP-prolog + +Prolog support for Sublime's [LSP](https://packagecontrol.io/packages/LSP) package, via +[scryer-prolog](https://github.com/mthom/scryer-prolog)'s built-in `--lsp` server. + +## Requirements + +* The [LSP](https://packagecontrol.io/packages/LSP) package. +* A build of scryer-prolog whose `--lsp` flag runs a language server over stdio. + As of this writing that support only exists in a development fork; the flag is + not yet in released/upstream scryer-prolog builds. Make sure `scryer-prolog` is + on your `PATH`, or set the `command` setting below to its full path. +* A Prolog syntax package that assigns the `source.prolog` scope to `.pl`/`.pro` files + (LSP-prolog itself does not ship syntax highlighting). + +## Installation + +Clone or copy this directory into your Sublime Text `Packages` folder as `LSP-prolog`, +then restart Sublime Text. + +## Configuration + +Open `Preferences > Package Settings > LSP > Servers > LSP-prolog` to edit settings. + +```jsonc +{ + "command": ["scryer-prolog", "--lsp"], + "selector": "source.prolog" +} +``` diff --git a/boot.py b/boot.py new file mode 100644 index 0000000..48f60a6 --- /dev/null +++ b/boot.py @@ -0,0 +1,18 @@ +from __future__ import annotations + + +def reload_plugin() -> None: + import sys + + prefix = "{}.".format(__package__) + + for module_name in tuple( + filter(lambda m: m.startswith(prefix) and m != __name__, sys.modules) + ): + del sys.modules[module_name] + + +reload_plugin() + + +from .plugin import * # noqa: F401, F403, E402 diff --git a/plugin/__init__.py b/plugin/__init__.py new file mode 100644 index 0000000..2c5cd8b --- /dev/null +++ b/plugin/__init__.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from LSP.plugin import register_plugin +from LSP.plugin import unregister_plugin + +from .plugin import ScryerProlog + +__all__ = ( + # ST: Core + "plugin_loaded", + "plugin_unloaded", +) + + +def plugin_loaded() -> None: + register_plugin(ScryerProlog) + + +def plugin_unloaded() -> None: + unregister_plugin(ScryerProlog) diff --git a/plugin/plugin.py b/plugin/plugin.py new file mode 100644 index 0000000..da77c1e --- /dev/null +++ b/plugin/plugin.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +from shutil import which + +from LSP.plugin import AbstractPlugin +from LSP.plugin import ClientConfig +from LSP.plugin import WorkspaceFolder +import sublime + + +class ScryerProlog(AbstractPlugin): + @classmethod + def name(cls) -> str: + return "prolog" + + @classmethod + def can_start( + cls, + window: sublime.Window, + initiating_view: sublime.View, + workspace_folders: list[WorkspaceFolder], + configuration: ClientConfig, + ) -> str | None: + command = configuration.command[0] if configuration.command else "scryer-prolog" + binary = sublime.expand_variables(command, {"packages": sublime.packages_path()}) + if which(binary): + return None + return ( + f'Could not find "{command}" on your PATH. LSP-prolog requires a build of scryer-prolog with ' + '"--lsp" support (see https://github.com/mthom/scryer-prolog). Install it, or set the "command" ' + "setting in LSP-prolog.sublime-settings to the full path of the binary." + )