Skip to content

Commit

Permalink
Add configurations and notes for Astro LS (#43)
Browse files Browse the repository at this point in the history
* Add configurations and notes for Astro LS
  • Loading branch information
S0AndS0 authored Sep 12, 2024
1 parent 2137715 commit 4b1fde4
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
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
```

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://git.luolix.topSogoCZE/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' ],
\ 'project_root_files': [ 'tsconfig.json', 'astro.config.mjs' ]
\ },
\ ]

0 comments on commit 4b1fde4

Please sign in to comment.