Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Oct 4, 2023
0 parents commit eca85d5
Show file tree
Hide file tree
Showing 39 changed files with 3,191 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "npm"
directory: "/server"
schedule:
interval: "daily"
groups:
vscode:
patterns:
- "vscode*"

- package-ecosystem: "npm"
directory: "/client"
schedule:
interval: "daily"
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build

on: [push, pull_request]

jobs:
tests:
name: JavaScript Test Action
runs-on: ubuntu-latest
strategy:
matrix:
node: [20]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Yarn install
run: yarn install

- name: Yarn build
run: yarn build
32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish

on:
release:
types:
- created

jobs:
publish:
name: Publish VSCode extension
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'

- name: Yarn install
run: yarn install

- name: Yarn build
run: yarn build

- name: Publish
run: yarn run deploy
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
client/out/
server/out/
node_modules/

.vscode-test/

*.vsix
*.tgz
*~

.DS_Store
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11.1
25 changes: 25 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.gitignore
.eslintrc
.eslintignore
.prettierrc.json
.node-version

**/*.ts
**/*.map
**/tsconfig.json
**/tsconfig.base.json

.vscode/**
.github/**
scripts/**

client/node_modules/**
!client/node_modules/vscode-jsonrpc/**
!client/node_modules/vscode-languageclient/**
!client/node_modules/vscode-languageserver-protocol/**
!client/node_modules/vscode-languageserver-types/**
!client/node_modules/brace-expansion/**
!client/node_modules/balanced-match/**
!client/node_modules/lru-cache/**
!client/node_modules/yallist/**
!client/node_modules/semver/**
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Marco Roth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Turbo LSP

Intelligent Turbo tooling for Visual Studio Code

![](/assets/turbo-lsp.png)

## Functionality

Currently, this Language Server only works for HTML, though its utility extends to various file types such as ERB, PHP, or Blade files.

### Completions

* Completions for Turbo HTML Custom Elements
* Completions for Turbo HTML Custom Element Attributes

## Structure

```
.
├── package.json // The extension manifest.
|
├── client // Language Client
│ └── src
│ └── extension.ts // Language Client entry point
|
└── server // Language Server
└── src
└── server.ts // Language Server entry point
```

## Running the extension locally

- Run `yarn install` in this folder. This installs all necessary npm modules in both the client and server folder
- Open VS Code on this folder.
- Press Ctrl+Shift+B to compile the client and server.
- Switch to the Debug viewlet.
- Select `Launch Client` from the drop down.
- Run the launch config.
- If you want to debug the server as well use the launch configuration `Attach to Server`
- In the [Extension Development Host] instance of VSCode, open a HTML file.
Binary file added assets/turbo-lsp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions assets/turbo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "vscode-turbo",
"description": "Intelligent Turbo tooling for Visual Studio Code",
"author": "Marco Roth",
"license": "MIT",
"version": "0.0.1",
"publisher": "Marco Roth",
"repository": {
"type": "git",
"url": "https://github.com/marcoroth/turbo-lsp"
},
"engines": {
"vscode": "^1.52.0"
},
"dependencies": {
"brace-expansion": "^4.0.0",
"minimatch": "^9.0.4",
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@types/vscode": "^1.52.0",
"typescript": "^5.4.5"
}
}
90 changes: 90 additions & 0 deletions client/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as path from "path"

import { workspace, ExtensionContext } from "vscode"
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from "vscode-languageclient/node"

export class Client {
private client: LanguageClient
private serverModule: string
private languageClientId = "languageServerTurbo"
private languageClientName = "Turbo LSP"
private context: ExtensionContext

constructor(context: ExtensionContext) {
this.context = context

this.serverModule = context.asAbsolutePath(path.join("server", "out", "server.js"))

this.client = new LanguageClient(
this.languageClientId,
this.languageClientName,
this.serverOptions,
this.clientOptions,
)
}

async start() {
try {
this.client.start()
} catch (error: any) {
console.error(`Error restarting the server: ${error.message}`)
return
}
}

async stop(): Promise<void> {
if (this.client) {
await this.client.stop()
}
}

async sendNotification(method: string, params: any) {
return await this.client.sendNotification(method, params)
}

async sendRequest<T>(method: string, params: any) {
return await this.client.sendRequest<T>(method, params)
}

// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
private get debugOptions() {
return {
execArgv: ["--nolazy", "--inspect=6009"],
}
}

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
private get serverOptions(): ServerOptions {
return {
run: {
module: this.serverModule,
transport: TransportKind.ipc,
},
debug: {
module: this.serverModule,
transport: TransportKind.ipc,
options: this.debugOptions,
},
}
}

private get clientOptions(): LanguageClientOptions {
return {
documentSelector: [
{ scheme: "file", language: "ruby" },
{ scheme: "file", language: "erb" },
{ scheme: "file", language: "blade" },
{ scheme: "file", language: "php" },
{ scheme: "file", language: "html" },
{ scheme: "file", language: "javascript" },
{ scheme: "file", language: "typescript" },
],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
}
}
}
18 changes: 18 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ExtensionContext } from "vscode"
import { Client } from "./client"

let client: Client

export async function activate(context: ExtensionContext) {
client = new Client(context)

await client.start()
}

export async function deactivate(): Promise<void> {
if (client) {
await client.stop()
} else {
return undefined
}
}
12 changes: 12 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2019",
"lib": ["ES2019"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit eca85d5

Please sign in to comment.