Code Monkey home page Code Monkey logo

language-tools's Introduction

Astro Language Tools

This repository contains all the editor tooling required for the Astro language (.astro files).

Notably, it contains an implementation of the Language Server Protocol (LSP) which as of now is used for the official VSCode Extension but could also be used to power a plugin for your favorite IDE in the future.

Packages

This repository is a monorepo managed through Turbo, which means that multiple packages are in this same repo (packages folder), here's a list:

The Astro language server, powered by Volar.

The official VS Code extension for Astro. This enables all of the editing features you depend on in VSCode for .astro files

TypeScript plugin to add support for .astro imports in .ts files with proper typing

Features provided

These packages together power editing functionality such as:

  • Go to Definition
  • Code hover hints
  • Code completion
  • Function signatures
  • Syntax highlighting
  • Code folding
  • Emmet

For a full list of features, see the VS Code's extension README.

Contributing

Pull requests of any size and any skill level are welcome, no contribution is too small. Changes to the Astro Language Tools are subject to Astro Governance and should adhere to the Astro Style Guide

See CONTRIBUTING.md for instructions on how to setup your development environment

Sponsors

Astro is generously supported by Netlify, Storyblok, and several other amazing organizations.

❤️ Sponsor Astro! ❤️

sponsors

language-tools's People

Contributors

beeb avatar bluwy avatar delucis avatar dreyfus92 avatar ematipico avatar fredkschott avatar github-actions[bot] avatar gooddaisy avatar goulvenclech avatar intagaming avatar johnsoncodehk avatar jonathantneal avatar juanm04 avatar juliusmarminge avatar lvqq avatar martrapp avatar matthewp avatar mikkel-t avatar moustaphadev avatar natemoo-re avatar okikio avatar oliverspeir avatar princesseuh avatar quraian avatar sciencefidelity avatar sebthom avatar ty3uk avatar virchau13 avatar voxelmc avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

language-tools's Issues

🤝 Publish the VSCode Extension to https://open-vsx.org

Checklist

  • I have already searched for existing issues for this framework/library.
  • I have already searched npm for an existing Astro integration.
  • I have already tried this with Astro myself, and it did not work.

Website or GitHub repository

https://open-vsx.org
https://github.com/eclipse/openvsx/wiki/Publishing-Extensions

Additional Details

This should hopefully just be an update to the publishing script for the vs code extension, though that doesn't mean it won't require a bit of work.

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

🐛 BUG: Undefined behavior when I pass children to a component that has no `<slot/>`

What package manager are you using?

npm

What operating system are you using?

mac

Describe the Bug

Given this component usage:

<WrapChildrenWithText>
  <img src="https://placehold.co/400" />
<WrapChildrenWithText>

I would expect this to warn or error if WrapChildrenWithText did not have a <slot> defined. Currently, I do not know what will happen other than we aren't providing warnings.

/cc @natemoo-re

Link to Minimal Reproducible Example (Optional)

No response

💡 RFC: Astro Language Server should automatically shim `Astro` global and infer `Astro.props`

Motivation

There are currently no types for the Astro global in an .astro file's frontmatter script.

Additionally, Astro.props currently must be cast. For example:

export interface Props {
  value: string;
}
const { value } = Astro.props as Props;

Proposed Solution

Astro's Language Server should:

  • Automatically inject type definitions for the Astro global into each file.
  • Automatically declare the value of Astro.props if export interface Props is detected.
  • Automatically provide Intellisense based on a component's Props when writing HTML

Detailed Design

No response

Open Questions

No response

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

🐛 BUG: id attribute breaks highlighting

Describe the Bug

Everything following the id becomes white as shown here:
image

Steps to Reproduce

Create an Astro component with the following content:

<div id={`a`}></div>

(I can literally see the bug right here in Github Markdown preview lol)

VSCode: Hover hint isn't working for Javascript inside script tags

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

Hover hint isn't working for Javascript inside script tags.

Steps to Reproduce

The VSCode extension should enable hover hints for Javascript inside script tags.

Link to Minimal Reproducible Example (Optional)

No response

VSCode: Autocomplete for JS, CSS/SCSS inside Astro components

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

Currently, autocomplete doesn't work for JavaScript inside the script tags, CSS, and SCSS inside Astro components.,

Steps to Reproduce

JavaScript Intellisense now works inside the frontmatter but not inside the script tags. It should work in both of the places. And CSS and SCSS IntelliSense should work inside the style tags.

Link to Minimal Reproducible Example (Optional)

No response

VSCode: Linting in Astro Components

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

The VSCode extension doesn't provide any linting in Astro components.

Steps to Reproduce

A custom Eslint parser should be set up for lining in the Astro components. It should have three types of linting enabled. First, for Javascript in the frontmatter. Then for HTML in the markup and for Javascript in the script tags. And then for Styling (CSS, SCSS, etc.) in the style tags. If possible, it should also have linting for Markdown inside the Markdown components.

Link to Minimal Reproducible Example (Optional)

No response

VSCode: Emmet isn't fully supported

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

Emmet support is incomplete in Astro components. Only basic completions are supported.

For example, if I type 'button' in a astro component, emmet only shows 'button' tag completion. But in JSX and HTML, it shows button, button:d, button:disabled, button:r, button:reset, button:s and button:submit tag completion.

Steps to Reproduce

Advance completions provide by Emmet should be suppported.

Link to Minimal Reproducible Example (Optional)

No response

Allow Types in JavaScript/TypeScript files

Background & Motivation

When creating a project that reexports Astro components, it would be nice if the types followinged, for example:

Name.astro

---
export interface Props {
  name: string;
}
---

index.ts

import Name from './Name.astro';

export {
  Name
};

However, currently the props do not follow through into TypeScript.

Proposed Solution

Build a TypeScript plugin which allows TypeScript files to consume Astro types.

Detailed Design

No response

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

🐛 BUG: `strict` tsconfig rule causes linting errors in `.astro` files

What package manager are you using?

yarn

What operating system are you using?

macOS

Describe the Bug

When using a tsconfig.json file such as :

{
   "compilerOptions": {
      "strict": true,
      "alwaysStrict": true
   }
}

Visual Studio Code highlights all of the JSX and shows this linting error:

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

image

In Discord, Matthew2 suspects this might be a bug with the Astro extension.

https://discord.com/channels/830184174198718474/845451724738265138/895704312544653353

Steps to Reproduce

  1. npm init astro --template minimal using template
  2. Open index.astro and note the lack of linting warnings.
  3. Add the tsconfig.json sample above.
  4. Close and then reopne index.astro.
  5. Notice all the linting errors.

Link to Minimal Reproducible Example (Optional)

https://github.com/justinnoel/astro-jsx-linting-issue

VSCode: JSX {} dynamic operator isn't higlighted

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

The JSX {} dynamic operator isn't higlighted

Steps to Reproduce

The JSX {} dynamic operator should be higlighted

Link to Minimal Reproducible Example (Optional)

No response

VSCode: doctype is not syntax highlighted

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

When using VSCode, the <!dotype html> element is not syntax highlighted.

Steps to Reproduce

n/a

Link to Minimal Reproducible Example (Optional)

No response

VSCode: References of mutable vaiables, arrays, properties, etc aren't bold

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

VSCode highlights immutable variables, functions, properties, arrays, etc with a dark blue color and mutable with a lighter blue color.

But the extension enables this highlighting only for the line you declare the immutable variable. But when you reference it in the script, it doesn't get highlighted.

Steps to Reproduce

In both the lines where you declare it and where you refer to it, an immutable variable should be highlighted with a dark blue color. And the mutable variables should be highlighted with a light blue color (current color shown in Astro components).

Link to Minimal Reproducible Example (Optional)

---
// Please view the code in VSCode. Highlighting in GitHub is different from VSCode

// The following variables are immutable and highlighed with a darker blue variant
const { name, description, version } = Astro.props;

// The following references of the immutable variables declared above aren't highlighted with a darker blue variant
const data = { name, description, version };

// The following reference of the data variable isn't highlighted with a darker blue variant
console.log(data);
---

VSCode: Components should be highlighted with a different color

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

Components are highlighted with the same color as general HTML codes.

Steps to Reproduce

Components should be highlighted with a different color.

Link to Minimal Reproducible Example (Optional)

No response

VSCode: Include prettier plugin

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

When the prettier plugin is ready, add it to VSCode automatically.

Steps to Reproduce

n/a

Link to Minimal Reproducible Example (Optional)

No response

🐛 BUG: The types of the imported components aren't updated

Describe the Bug

The types of the imported components aren't updated. I'm getting the same TypeErrors when I update the types of a component's prop.

Steps to Reproduce

The types of the imported components should be updated as soon as the user updates them

🐛 BUG: Make fetchContent default to `any`

Describe the Bug

When using fetchContent without providing a type parameter it is treated as unknown in which case accessing variables gives you type errors. We should use any as the default instead so that there are no type errors. You opt-in to strong typing by providing a type.

Steps to Reproduce

const thing = Astro.fetchContent('./something');

const val = thing[0].val;

🐛 BUG: Multiple comments cause unfound closing tag errors

Describe the Bug

If you have comments in nested elements it gets confused and thinks there are missing closing tags.

Steps to Reproduce

<html>
  <body class="is-preload">
    <!-- Wrapper -->
    <div id="wrapper">
      <!-- Main -->
      <div id="main"></div>
    </div>
  </body>
</html>

Import types from TypeScript/JavaScript into .astro files

Background & Motivation

I want to be able to import from packages like:

---
import { Something } from 'some/package';
---

Where the package has a ts/js entry that re-exports from other .astro files.

Proposed Solution

None

Detailed Design

No response

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

🐛 BUG: Broken sintax highlight for Stylus.

What version of astro are you using?

0.21.3

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

Syntax highlight doesn't seens to be working on Stylus on 0.21.0 and above, maybe this is a problem with Astro extension? I'm using the popular "Tokyo Night" theme, stylus is installed and it is working as expected functionality wise.

image
image

Link to Minimal Reproducible Example

https://codesandbox.io/s/beautiful-chaplygin-prpn3

VSCode: TypeScript errors are not displayed

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

When you have an error in the frontmatter TypeScript, the error is not shown.

Steps to Reproduce

---
let one = 'one';
let two = 2;

let three: number = one + two;
---

Link to Minimal Reproducible Example (Optional)

No response

🐛 BUG: Linting seems wrong for vanilla JS in astro components

What package manager are you using?

npm and yarn

What operating system are you using?

Mac

Describe the Bug

Linting seems off when using vanilla JS in astro components.

Here's an example page that fetches a dog image and renders it using vanilla JS:

dog.astro

<Layout> <!-- let's say this contains the html head and body elements -->
  <div id="dog"></div>
  <script type="text/javascript">
    /* let's not worry about browser support and just use modern JS */
    async function getDog() {
      try {
        const res = await fetch("https://dog.ceo/api/breeds/image/random");
        const data = await res.json();
        return data.message;
      } catch (error) {
        console.log(error);
        return null;
      }
    }
    async function renderDog() {
      const imgSrc = await getDog();
      if (imgSrc) {
        const parentElement = document.getElementById("dog");
        const imgElement = document.createElement("img");
        imgElement.src = imgSrc;
        parentElement.appendChild(imgElement);
      }
    }
    renderDog();
  </script>
</Layout>

This JS is valid, but here would be the output of astro check (same as the VSCode linting errors):

src/pages/index.astro:9:6 - Expression expected.
6        try {
         ~~~

src/pages/index.astro:10:8 - Expression expected.
7           const res = await fetch("https://dog.ceo/api/breeds/image/random");
            ~~~~~

src/pages/index.astro:13:6 - Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
10        } catch (error) {
          ~

src/pages/index.astro:16:6 - Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
13        }
          ~

src/pages/index.astro:17:4 - Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
14      }
        ~

src/pages/index.astro:19:6 - Expression expected.
16        const imgSrc = await getDog();
          ~~~~~

src/pages/index.astro:21:8 - Expression expected.
18          const parentElement = document.getElementById("dog");
            ~~~~~

src/pages/index.astro:25:6 - Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
22        }
          ~

src/pages/index.astro:26:4 - Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
23      }

Steps to Reproduce

  1. Go to the CodeSandbox reproduction
  2. Open a second terminal (you might need to fork it if you don't have permissions)
  3. Run yarn run check

Screenshot of the CodeSandbox showing astro vanilla JS linting issues

Link to Minimal Reproducible Example (Optional)

https://codesandbox.io/s/astro-js-linting-errors-1rttp

🐛 BUG: Conflicting ImportMeta declarations

Describe the Bug

This definition can conflict with my own environment's import.meta definitions. For example:

  • If I'm using Snowpack with @types/snowpack-env
  • If I'm using Vite and connected my tsconfig to vite/types

An example error that I'm seeing:

All declarations of 'hot' must have identical modifiers.js(2687)
Subsequent property declarations must have the same type.  Property 'hot' must be of type '{ readonly data: any; accept(): void; accept(cb: (mod: any) => void): void; accept(dep: string, cb: (mod: any) => void): void; accept(deps: readonly string[], cb: (mods: any[]) => void): void; acceptDeps(): never; dispose(cb: (data: any) => void): void; decline(): void; invalidate(): void; on: { ...; }; }', but h

I think it's safe to assume that your environment provides these, and its not the responsibility of the Astro compiler.

Steps to Reproduce

Do either of the steps above (for Snowpack or Vite) and then see this error in every compiled Astro file (ex: src/pages/index.astro).

🐛 BUG: Attribute prefixed with `@` breaks highlighting

Describe the Bug

The following Component is valid.

<XElement @is="div">Hello, world!</XElement>

The following HTML element is also valid:

<custom-element @is="div">Hello, world!</custom-element>

However, the @ prefixed attribute is not picked up by syntax highlighting, and will report the following error:

Identifier expected. js(1003)

This will cause the remainder of the element to be interpreted incorrectly. The following error is reported for the closing of the opening tag:

Unexpected token. Did you mean `{'>'}` or `&gt;`?

Steps to Reproduce

  1. npm init astro using template minimal
  2. Add <custom-element @is="div">Hello, world!</custom-element> to index.astro
  3. Error! Syntax highlighting is missing and the aforementioned errors are reported.

VSCode: cmd-click to open resources in /public

Background & Motivation

It would be great to be able to cmd+click on absolute paths to resources in /public from within astro components. So, for example, clicking on the path in <img src="/images/hero.svg"/> would open up /public/images/hero.svg.

Proposed Solution

Possible solutions

Incorporate into VSCode extension.

Detailed Design

No response

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

🐛 BUG: Importing images displayed an error

Describe the Bug

import logo from "../../public/logo.png";
// Cannot find module '../../public/logo.png' or its corresponding type declarations

Steps to Reproduce

  1. Import any image.
  2. See error

🐛 BUG: Using fetch results in an error

Describe the Bug

---
const data = await fetch("url")
// Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher
---

Steps to Reproduce

  1. Use fetch in the component script section.

VSCode : Peek Definitions

Background & Motivation

This is something I do, when I spend most of my time just reading code, is peeking into the source files for API's to see whats under the hood.

This would also be a nice feature to have with the Astro Language extension, where it would apply to looking up components and functions written in the body of the astro file and in the frontmatter block

Proposed Solution

Open Questions

I truly dont know enough to make any suggestions regarding a solution for this particular problem,

Detailed Design

This is the reference to the VSCode docs that describes the feature in more detail:

https://code.visualstudio.com/docs/editor/editingevolved#_peek

And the reference to the API

https://code.visualstudio.com/api/references/vscode-api#DefinitionProvider

I also noticed that this API could be related to the request snowpackjs/astro#1024 and a bit wider afield where we can define the symbols used in the astro files, this can help with the Outline dialog box in the editor window of VSCode

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

VSCode : F2 - rename component

Background & Motivation

Inside VS Code, the F2 keybinding allows for symbols to be renamed throughout the file.

---
import timer from 'timer'
const date = timer()
---

<div>
    {date.now()}
</div>

In this instance if we wanted to rename date a current workflow would be to search and replace the terms with the new substituted term, whereas the keybinding prefroms this step for the developer.

Proposed Solution

Possible solutions

I propose that this functionality be provided within the Astro language extension.

Alternatives considered

Risks, downsides, and/or tradeoffs

Current work around is to do either a grep of the file or use the editors search and replace function

Open Questions

Detailed Design

further information about this is found on the VS code Docs here: https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol

This is the API for the 'Rename Provider'
https://code.visualstudio.com/api/references/vscode-api#RenameProvider

I would like to help, but this is so far beyond my mere mortalness

Help make it happen!

  • I am willing to submit a PR to implement this change.
  • I am willing to submit a PR to implement this change, but would need some guidance.
  • I am not willing to submit a PR to implement this change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.