It allows doing gf on "src/components/Foo.astro", "./Foo.astro", "../bar/Baz.astro" in the front matter. It also allows doing :find *Foo<Tab> for the simple cases.
It also helps resolving includes for include/definition search.
suffixesadd is a mix of all the values found in $VIMRUNTIME/ftplugin/{javascript,typescript,css,sass,html}.vim, plus some Astro-specific ones.
It tells Vim what extensions to try for extension-less filenames. This allows doing gf on <Foo /> in a template for the simple cases.
b:astro_paths is populated by astro#CollectPathsFromConfig() with a list of all the aliases defined in tsconfig.json or jsconfig.json. This is not directly useful for the user but useful for the next option.
includeexpr is executed if the target is not found. It is bound to astro#AstroInclude(), which replaces the alias in the filename with the corresponding path.
So, in addition to the simple cases, it also handles cases like "@components/Foo.astro" for gf, include/definition search, etc.
include is set to a value that should work for ESM imports like import Foo from "..., import type Foo from "..., or import "....
It allows things like [<C-i> on a type, etc.
define is set to a value that mixes the default values for JavaScript and SASS.
It should help locating definitions in local and included files with commands like [D or :dsearch.
Scoped comment formats
astro#Comments() set comments and commentstring to the appropriate value for the current scope. The implementation honestly looks like it should be slow but it only takes a couple of milliseconds and I didn't notice any performance issue.
I did this for tpope/commentary, which uses commentstring.
Note: it only covers SASS/SCSS/CSS, JS/TS, and HTML at the moment.
This pull request adds two files:
ftplugin/astro.vim
andautoload/astro.vim
.Overview
ftplugin/astro.vim
enables/fine-tunes the following features:formatoptions
,path
,define
,include
,includeexpr
,suffixesadd
, andb:astro_paths
,%
, viamatchpairs
,b:match_ignorecase
, andb:match_words
,iskeyword
,comments
andcommentstring
,CursorMoved
autocommand.autoload/astro.vim
hosts the following support functions:astro#IdentifyScope()
andastro#Comments()
, define the propercomments
andcommentstring
for the current scope,astro#CollectPathsFromConfig()
, collects aliases defined intsconfig.json
for use in the function below,astro#AstroInclude()
, replaces aliases in filenames for:find
,gf
, etc.Details
Project-wide navigation
path
is set according to https://docs.astro.build/en/core-concepts/project-structure/#directories-and-files.It allows doing
gf
on"src/components/Foo.astro"
,"./Foo.astro"
,"../bar/Baz.astro"
in the front matter. It also allows doing:find *Foo<Tab>
for the simple cases.It also helps resolving includes for include/definition search.
suffixesadd
is a mix of all the values found in$VIMRUNTIME/ftplugin/{javascript,typescript,css,sass,html}.vim
, plus some Astro-specific ones.It tells Vim what extensions to try for extension-less filenames. This allows doing
gf
on<Foo />
in a template for the simple cases.b:astro_paths
is populated byastro#CollectPathsFromConfig()
with a list of all the aliases defined intsconfig.json
orjsconfig.json
. This is not directly useful for the user but useful for the next option.includeexpr
is executed if the target is not found. It is bound toastro#AstroInclude()
, which replaces the alias in the filename with the corresponding path.So, in addition to the simple cases, it also handles cases like
"@components/Foo.astro"
forgf
, include/definition search, etc.include
is set to a value that should work for ESM imports likeimport Foo from "...
,import type Foo from "...
, orimport "...
.It allows things like
[<C-i>
on a type, etc.define
is set to a value that mixes the default values for JavaScript and SASS.It should help locating definitions in local and included files with commands like
[D
or:dsearch
.Scoped comment formats
astro#Comments()
setcomments
andcommentstring
to the appropriate value for the current scope. The implementation honestly looks like it should be slow but it only takes a couple of milliseconds and I didn't notice any performance issue.I did this for
tpope/commentary
, which usescommentstring
.Note: it only covers SASS/SCSS/CSS, JS/TS, and HTML at the moment.
Tested in Vim 9.0.270 and Vim 9.0472 on a Mac.