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

Add configurations and notes for Astro LS #43

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ by YCM, though they should work for the most part.
* [CSS](#css)
* [PHP](#php)
* [Crystal](#crystal)
* [Astro](#astro)
* [Known Issues](#known-issues)

<!-- Added by: ben, at: Tue 21 Feb 2023 09:01:14 GMT -->
Expand Down Expand Up @@ -347,6 +348,53 @@ let g:ycm_language_server =
Place crystalline in the path (i.e. /usr/local/bin) or use absolute path
in the example above..

# Astro

In addition to defining `g:ycm_language_server` block as shown in
[`astro/snippet.vim`](astro/snippet.vim) this LSP requires `.ycm_extra_conf.py`
to pass Language Server `initializationOptions` pointing to a directory
containing either `typescript.js` or `tsserverlibrary.js` file, such as
`node_modules/typescript/lib`, via `typescript.tsdk` key/value address, eg.

```python
import os

def Settings( **kwargs ):
current_directory = os.path.abspath(os.path.curdir)
if kwargs[ 'language' ] == 'astro':
configs = {
'ls': {
'typescript': {
'tsdk': f"{current_directory}/node_modules/typescript/lib"
},
},
}

return configs
```

... Authors of Astro Language Server recommend installing `prettier` plugins
too, so adding the following to your `npm init` rituals may be a good idea;

```bash
npm install --save-dev typescript prettier prettier-plugin-astro @astrojs/ts-plugin
bstaletic marked this conversation as resolved.
Show resolved Hide resolved
```

Finally, hopefully for now, adding the `@astrojs/ts-plugin` to your project's
`tsconfig.json` may be necessary to enable all features of Astro LS

```json
{
"compilerOptions": {
"plugins": [
{
"name": "@astrojs/ts-plugin"
}
]
}
}
```

# Jai

This is using [Jails](https://github.comSogoCZE/Jails), which is very much
Expand Down
53 changes: 53 additions & 0 deletions astro/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import subprocess, os, sys, platform

def OnWindows():
return platform.system() == 'Windows'


# On Windows, distutils.spawn.find_executable only works for .exe files
# but .bat and .cmd files are also executables, so we use our own
# implementation.
def FindExecutable( executable ):
# Executable extensions used on Windows
WIN_EXECUTABLE_EXTS = [ '.exe', '.bat', '.cmd' ]

paths = os.environ[ 'PATH' ].split( os.pathsep )
base, extension = os.path.splitext( executable )

if OnWindows() and extension.lower() not in WIN_EXECUTABLE_EXTS:
extensions = WIN_EXECUTABLE_EXTS
else:
extensions = [ '' ]

for extension in extensions:
executable_name = executable + extension
if not os.path.isfile( executable_name ):
for path in paths:
executable_path = os.path.join( path, executable_name )
if os.path.isfile( executable_path ):
return executable_path
else:
return executable_name
return None


def FindExecutableOrDie( executable, message ):
path = FindExecutable( executable )

if not path:
sys.exit( "ERROR: Unable to find executable '{0}'. {1}".format(
executable,
message ) )

return path


def Main():
npm = FindExecutableOrDie( 'npm', 'npm is required to set up Astro LS.' )
subprocess.check_call( [ npm, 'install', '--production' ] )


if __name__ == '__main__':
Main()
6 changes: 6 additions & 0 deletions astro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "ycmd astro-ls runtime area",
"dependencies": {
"@astrojs/language-server": "*"
}
}
8 changes: 8 additions & 0 deletions astro/snippet.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let g:ycm_language_server += [
\ {
\ 'name': 'astro',
\ 'filetypes': [ 'astro' ],
\ 'cmdline': [ expand( g:ycm_lsp_dir . '/astro/node_modules/@astrojs/language-server/bin/nodeServer.js' ), '--stdio' ],
bstaletic marked this conversation as resolved.
Show resolved Hide resolved
\ 'project_root_files': [ 'tsconfig.json', 'astro.config.mjs' ]
\ },
\ ]