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

✨ Format on save #24

Merged
merged 16 commits into from
Jul 16, 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
14 changes: 11 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '21'
cache: 'yarn'

- name: Install dependencies
run: yarn install

- name: Format
run: yarn format

- name: Lint
run: yarn lint

- name: Test
run: yarn test
- name: Build
run: yarn pretest

# TODO: add integration tests when we have them

- name: Test grammar
run: yarn test-grammar
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# vscode
*.vsix
.vscode-test/
build/
dist/
out/

# asdf
Expand Down
5 changes: 5 additions & 0 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
});
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"ms-azuretools.vscode-docker",
"ms-vscode.extension-test-runner",
"ms-vscode-remote.remote-containers",
"ms-vscode.extension-test-runner",
"redhat.vscode-yaml"
]
}
16 changes: 15 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--workspaceFolder=${workspaceFolder}/tests"
]
],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Run Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
13 changes: 12 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
// Disable bracket colorization for testing
"editor.bracketPairColorization.enabled": false
"editor.bracketPairColorization.enabled": false,
"files.exclude": {
"dist": false,
"out": false
},
"search.exclude": {
"yarn.lock": true
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"eslint.useFlatConfig": true,
"search.useIgnoreFiles": true
}
37 changes: 37 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "watch-tests",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": "build"
},
{
"label": "tasks: watch-tests",
"dependsOn": ["npm: watch", "npm: watch-tests"],
"problemMatcher": []
}
]
}
13 changes: 11 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
.devcontainer/**
.vscode/**
assets/**
tests/**
build/**
node_modules/**
out/**
src/**
**/tsconfig.json
**/.prettier*
.vscode-test.mjs
CONTRIBUTING.md
Docker*
*docker*
vsc-extension-quickstart.md
eslint.config.mjs
justfile
tsconfig.json
webpack.config.js
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

### Added

- Format on save
- Typescript config

## [0.4.0] - 2024-07-08

### Added
Expand Down
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,3 @@ This page lists the steps needed to set up a development environment and contrib
5. Install the [recommended VSCode extensions](.vscode/extensions.json).

6. Launch the extension in test mode via VSCode debug launch profile.

## Additional notes

See also the auto generated [quickstart guide](vsc-extension-quickstart.md).
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM node:21-alpine

ENV YARN_CACHE_FOLDER=/root/.yarn

RUN apk add just
# TODO: add xvfb for integration tests
RUN apk update && \
apk add just

WORKDIR /code
COPY package.json yarn.lock ./
Expand Down
8 changes: 4 additions & 4 deletions assets/example.just
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set tempdir := "/tmp"

export MY_VAR := `./my_script.sh`

[confirm: "Continue?"]
@foo PARAM_1="hello" PARAM_2="world" +ARGS:
[confirm("Continue?")]
@foo PARAM_1="hello" PARAM_2="world" +ARGS="":
echo {{ PARAM_1 }} {{ PARAM_2 }} {{ ARGS }}

python:
#!/usr/bin/env python3
print('Hello from python!')
#!/usr/bin/env python3
print('Hello from python!')
57 changes: 57 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import unusedImports from 'eslint-plugin-unused-imports';
import tseslint from 'typescript-eslint';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const config = [
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
),
{
ignores: ['.vscode-test', '**/build/', '**/dist/', '**/node_modules/', '**/out/'],
},
{
plugins: {
'@typescript-eslint': typescriptEslint,
'simple-import-sort': simpleImportSort,
'unused-imports': unusedImports,
},
languageOptions: {
parser: tsParser,
ecmaVersion: 2022,
sourceType: 'module',
parserOptions: {
project: './tsconfig.json',
},
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'unused-imports/no-unused-imports': 'error',
'no-unused-vars': 'off',
'unused-imports/no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
},
},
];

export default tseslint.config(...config, {
files: ['.vscode-test.mjs'],
extends: [tseslint.configs.disableTypeChecked],
});
14 changes: 11 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ build +ARGS="":

test +ARGS="":
docker compose run --rm dev /bin/sh -c \
"yarn test {{ ARGS }}"
"yarn pretest {{ ARGS }}"
# TODO: setup xvfb for running tests in container/ci
# docker compose run --rm dev /bin/sh -c \
# "xvfb-run -a yarn test-extension {{ ARGS }}"
docker compose run --rm dev /bin/sh -c \
"yarn test-grammar {{ ARGS }}"

lint:
docker compose run --rm dev /bin/sh -c \
"just --fmt --unstable"
docker compose run --rm dev /bin/sh -c \
"yarn lint --write"
"yarn format --write"
docker compose run --rm dev /bin/sh -c \
"yarn lint --fix"

translate:
docker compose run --rm dev /bin/sh -c \
"yarn --silent js-yaml syntaxes/just.tmLanguage.yml > syntaxes/just.tmLanguage.json"
docker compose run --rm dev /bin/sh -c "yarn --silent gen-scopes"

package +ARGS="":
just translate
docker compose run --rm dev /bin/sh -c \
"mkdir -p out && yarn vsce package --yarn --out out/ {{ ARGS }}"
"mkdir -p build && yarn package && yarn vsce package --yarn --out build/ {{ ARGS }}"

console:
-docker compose run --rm dev /bin/sh
Expand Down
53 changes: 48 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
"license": "MIT",
"version": "0.4.0",
"engines": {
"node": ">=16.0.0",
"node": ">=21.1.0 || ^20.9.0 || ^18.18.0",
"vscode": ">=1.85.0"
},
"scripts": {
"lint": "prettier --cache .",
"test": "vscode-tmgrammar-snap tests/**/*.just",
"gen-scopes": "node syntaxes/gen_scopes.js"
"compile-extension": "webpack",
"watch": "webpack --watch --verbose",
"package": "webpack --mode production --devtool hidden-source-map",
"compile": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "yarn compile && yarn compile-extension",
"test-extension": "vscode-test --disable-extensions",
"test-grammar": "vscode-tmgrammar-snap syntaxes/tests/**/*.just",
"format": "prettier --log-level warn --cache .",
"lint": "eslint . --cache --cache-location node_modules/.cache/eslint",
"gen-scopes": "yarn compile && node out/gen_scopes.js"
},
"categories": [
"Programming Languages"
Expand All @@ -27,6 +35,7 @@
"scripts"
],
"icon": "icons/robot.png",
"main": "./dist/extension.js",
"contributes": {
"languages": [
{
Expand Down Expand Up @@ -54,12 +63,46 @@
"scopeName": "source.just",
"path": "./syntaxes/just.tmLanguage.json"
}
],
"configuration": {
"properties": {
"vscode-just.formatOnSave": {
"type": "boolean",
"default": false,
"description": "Enable/disable format on save (currently unstable)"
},
"vscode-just.justPath": {
"type": "string",
"default": "just",
"description": "Path to just binary"
}
}
},
"commands": [
{
"command": "vscode-just.formatDocument",
"title": "Just: Format Document"
}
]
},
"devDependencies": {
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.10",
"@types/vscode": "^1.91.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"@vscode/vsce": "^2.22.0",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.0.0",
"js-yaml": "^4.1.0",
"prettier": "^3.2.4",
"vscode-tmgrammar-test": "^0.1.3"
"ts-loader": "^9.5.1",
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.0",
"vscode-tmgrammar-test": "^0.1.3",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4"
}
}
Loading