purescript: Extract to zed-extensions/purescript repository (#26571)
This PR extracts the PureScript extension to the [zed-extensions/purescript](https://github.com/zed-extensions/purescript) repository. Release Notes: - N/A
This commit is contained in:
parent
21cf2e38c5
commit
5858e61327
11 changed files with 1 additions and 302 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -17204,13 +17204,6 @@ dependencies = [
|
||||||
"zed_extension_api 0.1.0",
|
"zed_extension_api 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zed_purescript"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"zed_extension_api 0.1.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed_ruff"
|
name = "zed_ruff"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -174,7 +174,6 @@ members = [
|
||||||
"extensions/html",
|
"extensions/html",
|
||||||
"extensions/perplexity",
|
"extensions/perplexity",
|
||||||
"extensions/proto",
|
"extensions/proto",
|
||||||
"extensions/purescript",
|
|
||||||
"extensions/ruff",
|
"extensions/ruff",
|
||||||
"extensions/slash-commands-example",
|
"extensions/slash-commands-example",
|
||||||
"extensions/snippets",
|
"extensions/snippets",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# PureScript
|
# PureScript
|
||||||
|
|
||||||
PureScript support is available through the [PureScript extension](https://github.com/zed-industries/zed/tree/main/extensions/purescript).
|
PureScript support is available through the [PureScript extension](https://github.com/zed-extensions/purescript).
|
||||||
|
|
||||||
- Tree-sitter: [postsolar/tree-sitter-purescript](https://github.com/postsolar/tree-sitter-purescript)
|
- Tree-sitter: [postsolar/tree-sitter-purescript](https://github.com/postsolar/tree-sitter-purescript)
|
||||||
- Language-Server: [nwolverson/purescript-language-server](https://github.com/nwolverson/purescript-language-server)
|
- Language-Server: [nwolverson/purescript-language-server](https://github.com/nwolverson/purescript-language-server)
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "zed_purescript"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition.workspace = true
|
|
||||||
publish.workspace = true
|
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/purescript.rs"
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
zed_extension_api = "0.1.0"
|
|
|
@ -1 +0,0 @@
|
||||||
../../LICENSE-APACHE
|
|
|
@ -1,15 +0,0 @@
|
||||||
id = "purescript"
|
|
||||||
name = "PureScript"
|
|
||||||
description = "PureScript support."
|
|
||||||
version = "0.1.0"
|
|
||||||
schema_version = 1
|
|
||||||
authors = ["Iván Molina Rebolledo <ivanmolinarebolledo@gmail.com>"]
|
|
||||||
repository = "https://github.com/zed-industries/zed"
|
|
||||||
|
|
||||||
[language_servers.purescript-language-server]
|
|
||||||
name = "PureScript Language Server"
|
|
||||||
language = "PureScript"
|
|
||||||
|
|
||||||
[grammars.purescript]
|
|
||||||
repository = "https://github.com/postsolar/tree-sitter-purescript"
|
|
||||||
commit = "0554811a512b9cec08b5a83ce9096eb22da18213"
|
|
|
@ -1,3 +0,0 @@
|
||||||
("(" @open ")" @close)
|
|
||||||
("[" @open "]" @close)
|
|
||||||
("{" @open "}" @close)
|
|
|
@ -1,14 +0,0 @@
|
||||||
name = "PureScript"
|
|
||||||
grammar = "purescript"
|
|
||||||
path_suffixes = ["purs"]
|
|
||||||
autoclose_before = ",=)}]"
|
|
||||||
line_comments = ["-- "]
|
|
||||||
block_comment = ["{- ", " -}"]
|
|
||||||
brackets = [
|
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
|
||||||
{ start = "[", end = "]", close = true, newline = true },
|
|
||||||
{ start = "(", end = ")", close = true, newline = true },
|
|
||||||
{ start = "\"", end = "\"", close = true, newline = false },
|
|
||||||
{ start = "'", end = "'", close = true, newline = false },
|
|
||||||
{ start = "`", end = "`", close = true, newline = false },
|
|
||||||
]
|
|
|
@ -1,144 +0,0 @@
|
||||||
;; Copyright 2022 nvim-treesitter
|
|
||||||
;;
|
|
||||||
;; Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
;; you may not use this file except in compliance with the License.
|
|
||||||
;; You may obtain a copy of the License at
|
|
||||||
;;
|
|
||||||
;; http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
;;
|
|
||||||
;; Unless required by applicable law or agreed to in writing, software
|
|
||||||
;; distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
;; See the License for the specific language governing permissions and
|
|
||||||
;; limitations under the License.
|
|
||||||
|
|
||||||
;; ----------------------------------------------------------------------------
|
|
||||||
;; Literals and comments
|
|
||||||
|
|
||||||
(integer) @number
|
|
||||||
(exp_negation) @number
|
|
||||||
(exp_literal (number)) @float
|
|
||||||
(char) @string
|
|
||||||
[
|
|
||||||
(string)
|
|
||||||
(triple_quote_string)
|
|
||||||
] @string
|
|
||||||
|
|
||||||
(comment) @comment
|
|
||||||
|
|
||||||
|
|
||||||
;; ----------------------------------------------------------------------------
|
|
||||||
;; Punctuation
|
|
||||||
|
|
||||||
[
|
|
||||||
"("
|
|
||||||
")"
|
|
||||||
"{"
|
|
||||||
"}"
|
|
||||||
"["
|
|
||||||
"]"
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
[
|
|
||||||
(comma)
|
|
||||||
";"
|
|
||||||
] @punctuation.delimiter
|
|
||||||
|
|
||||||
|
|
||||||
;; ----------------------------------------------------------------------------
|
|
||||||
;; Keywords, operators, includes
|
|
||||||
|
|
||||||
[
|
|
||||||
"forall"
|
|
||||||
"∀"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
;; (pragma) @constant
|
|
||||||
|
|
||||||
[
|
|
||||||
"if"
|
|
||||||
"then"
|
|
||||||
"else"
|
|
||||||
"case"
|
|
||||||
"of"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
[
|
|
||||||
"import"
|
|
||||||
"module"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
[
|
|
||||||
(operator)
|
|
||||||
(constructor_operator)
|
|
||||||
(type_operator)
|
|
||||||
(qualified_module) ; grabs the `.` (dot), ex: import System.IO
|
|
||||||
(all_names)
|
|
||||||
(wildcard)
|
|
||||||
"="
|
|
||||||
"|"
|
|
||||||
"::"
|
|
||||||
"=>"
|
|
||||||
"->"
|
|
||||||
"<-"
|
|
||||||
"\\"
|
|
||||||
"`"
|
|
||||||
"@"
|
|
||||||
"∷"
|
|
||||||
"⇒"
|
|
||||||
"<="
|
|
||||||
"⇐"
|
|
||||||
"→"
|
|
||||||
"←"
|
|
||||||
] @operator
|
|
||||||
|
|
||||||
(module) @title
|
|
||||||
|
|
||||||
[
|
|
||||||
(where)
|
|
||||||
"let"
|
|
||||||
"in"
|
|
||||||
"class"
|
|
||||||
"instance"
|
|
||||||
"derive"
|
|
||||||
"foreign"
|
|
||||||
"data"
|
|
||||||
"newtype"
|
|
||||||
"type"
|
|
||||||
"as"
|
|
||||||
"hiding"
|
|
||||||
"do"
|
|
||||||
"ado"
|
|
||||||
"infix"
|
|
||||||
"infixl"
|
|
||||||
"infixr"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
|
|
||||||
;; ----------------------------------------------------------------------------
|
|
||||||
;; Functions and variables
|
|
||||||
|
|
||||||
(variable) @variable
|
|
||||||
(pat_wildcard) @variable
|
|
||||||
|
|
||||||
(signature name: (variable) @type)
|
|
||||||
(function
|
|
||||||
name: (variable) @function
|
|
||||||
patterns: (patterns))
|
|
||||||
|
|
||||||
|
|
||||||
(exp_infix (exp_name) @function (#set! "priority" 101))
|
|
||||||
(exp_apply . (exp_name (variable) @function))
|
|
||||||
(exp_apply . (exp_name (qualified_variable (variable) @function)))
|
|
||||||
|
|
||||||
|
|
||||||
;; ----------------------------------------------------------------------------
|
|
||||||
;; Types
|
|
||||||
|
|
||||||
(type) @type
|
|
||||||
(type_variable) @type
|
|
||||||
|
|
||||||
(constructor) @constructor
|
|
||||||
|
|
||||||
; True or False
|
|
||||||
((constructor) @_bool (#match? @_bool "(True|False)")) @boolean
|
|
|
@ -1,3 +0,0 @@
|
||||||
(_ "[" "]" @end) @indent
|
|
||||||
(_ "{" "}" @end) @indent
|
|
||||||
(_ "(" ")" @end) @indent
|
|
|
@ -1,97 +0,0 @@
|
||||||
use std::{env, fs};
|
|
||||||
use zed_extension_api::{self as zed, serde_json, Result};
|
|
||||||
|
|
||||||
const SERVER_PATH: &str = "node_modules/.bin/purescript-language-server";
|
|
||||||
const PACKAGE_NAME: &str = "purescript-language-server";
|
|
||||||
|
|
||||||
struct PurescriptExtension {
|
|
||||||
did_find_server: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PurescriptExtension {
|
|
||||||
fn server_exists(&self) -> bool {
|
|
||||||
fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn server_script_path(&mut self, language_server_id: &zed::LanguageServerId) -> Result<String> {
|
|
||||||
let server_exists = self.server_exists();
|
|
||||||
if self.did_find_server && server_exists {
|
|
||||||
return Ok(SERVER_PATH.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
zed::set_language_server_installation_status(
|
|
||||||
language_server_id,
|
|
||||||
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
|
|
||||||
);
|
|
||||||
let version = zed::npm_package_latest_version(PACKAGE_NAME)?;
|
|
||||||
|
|
||||||
if !server_exists
|
|
||||||
|| zed::npm_package_installed_version(PACKAGE_NAME)?.as_ref() != Some(&version)
|
|
||||||
{
|
|
||||||
zed::set_language_server_installation_status(
|
|
||||||
language_server_id,
|
|
||||||
&zed::LanguageServerInstallationStatus::Downloading,
|
|
||||||
);
|
|
||||||
let result = zed::npm_install_package(PACKAGE_NAME, &version);
|
|
||||||
match result {
|
|
||||||
Ok(()) => {
|
|
||||||
if !self.server_exists() {
|
|
||||||
Err(format!(
|
|
||||||
"installed package '{PACKAGE_NAME}' did not contain expected path '{SERVER_PATH}'",
|
|
||||||
))?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
if !self.server_exists() {
|
|
||||||
Err(error)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.did_find_server = true;
|
|
||||||
Ok(SERVER_PATH.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl zed::Extension for PurescriptExtension {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
did_find_server: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn language_server_command(
|
|
||||||
&mut self,
|
|
||||||
language_server_id: &zed::LanguageServerId,
|
|
||||||
_worktree: &zed::Worktree,
|
|
||||||
) -> Result<zed::Command> {
|
|
||||||
let server_path = self.server_script_path(language_server_id)?;
|
|
||||||
Ok(zed::Command {
|
|
||||||
command: zed::node_binary_path()?,
|
|
||||||
args: vec![
|
|
||||||
env::current_dir()
|
|
||||||
.unwrap()
|
|
||||||
.join(&server_path)
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string(),
|
|
||||||
"--stdio".to_string(),
|
|
||||||
],
|
|
||||||
env: Default::default(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn language_server_initialization_options(
|
|
||||||
&mut self,
|
|
||||||
_language_server_id: &zed::LanguageServerId,
|
|
||||||
_worktree: &zed::Worktree,
|
|
||||||
) -> Result<Option<serde_json::Value>> {
|
|
||||||
Ok(Some(serde_json::json!({
|
|
||||||
"purescript": {
|
|
||||||
"addSpagoSources": true
|
|
||||||
}
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zed::register_extension!(PurescriptExtension);
|
|
Loading…
Add table
Add a link
Reference in a new issue