-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
231 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# local test file | ||
*.wasm | ||
.swcrc | ||
.swc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
// @ts-nocheck | ||
const style = css` | ||
:host { | ||
color: red; | ||
color: ${' red'}; | ||
} | ||
` | ||
const style2 = css({ | ||
$: ` | ||
color: ${' red'}; | ||
` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
// @ts-nocheck | ||
const style = css`:host {color: red;}` | ||
const style = css`:host{color:${' red'};}`; | ||
const style2 = css({ | ||
$: `color:${' red'};` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ authors = ["mantou132 <[email protected]>"] | |
repository = "https://github.com/mantou132/gem" | ||
snippets = "./snippets/typescript.json" | ||
|
||
[grammars.typescript] | ||
repository = "https://github.com/tree-sitter/tree-sitter-typescript" | ||
commit = "f975a621f4e7f532fe322e13c4f79495e0a7b2e7" | ||
[language_servers.gem] | ||
name = "Gem language server" | ||
languages = ["TypeScript", "TSX", "JavaScript", "JSDoc"] | ||
language_ids = { "TypeScript" = "typescript", "TSX" = "typescriptreact", "JavaScript" = "javascript" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,99 @@ | ||
use zed_extension_api as zed; | ||
///! html: emmet + html | ||
///! css: css | ||
use std::{env, fs}; | ||
use zed::settings::LspSettings; | ||
use zed_extension_api::{self as zed, LanguageServerId, Result}; | ||
|
||
struct MyExtension { | ||
// ... state | ||
const NPM_PKG_NAME: &str = "vscode-gem-languageservice"; | ||
const LS_BIN_PATH: &str = "node_modules/.bin/vscode-gem-languageservice"; | ||
|
||
#[derive(Default)] | ||
struct GemExtension { | ||
did_find_server: bool, | ||
} | ||
|
||
impl zed::Extension for MyExtension { | ||
fn new() -> Self | ||
where | ||
Self: Sized, | ||
{ | ||
MyExtension {} | ||
impl GemExtension { | ||
fn server_exists(&self) -> bool { | ||
fs::metadata(LS_BIN_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(LS_BIN_PATH.to_string()); | ||
} | ||
|
||
zed::set_language_server_installation_status( | ||
language_server_id, | ||
&zed::LanguageServerInstallationStatus::CheckingForUpdate, | ||
); | ||
let version = zed::npm_package_latest_version(NPM_PKG_NAME)?; | ||
|
||
if !server_exists | ||
|| zed::npm_package_installed_version(NPM_PKG_NAME)?.as_ref() != Some(&version) | ||
{ | ||
zed::set_language_server_installation_status( | ||
language_server_id, | ||
&zed::LanguageServerInstallationStatus::Downloading, | ||
); | ||
let result = zed::npm_install_package(NPM_PKG_NAME, &version); | ||
match result { | ||
Ok(()) => { | ||
if !self.server_exists() { | ||
Err(format!( | ||
"installed package '{NPM_PKG_NAME}' did not contain expected path '{LS_BIN_PATH}'", | ||
))?; | ||
} | ||
} | ||
Err(error) => { | ||
if !self.server_exists() { | ||
Err(error)?; | ||
} | ||
} | ||
} | ||
} | ||
|
||
self.did_find_server = true; | ||
Ok(LS_BIN_PATH.to_string()) | ||
} | ||
} | ||
|
||
impl zed::Extension for GemExtension { | ||
fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
fn language_server_command( | ||
&mut self, | ||
language_server_id: &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_workspace_configuration( | ||
&mut self, | ||
server_id: &LanguageServerId, | ||
worktree: &zed::Worktree, | ||
) -> Result<Option<zed::serde_json::Value>> { | ||
let settings = LspSettings::for_worktree(server_id.as_ref(), worktree) | ||
.ok() | ||
.and_then(|lsp_settings| lsp_settings.settings.clone()) | ||
.unwrap_or_default(); | ||
Ok(Some(settings)) | ||
} | ||
} | ||
|
||
zed::register_extension!(MyExtension); | ||
zed::register_extension!(GemExtension); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters