generated from orta/TypeScript-TSServer-Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from webNeat/develop
Alpha version
- Loading branch information
Showing
18 changed files
with
222 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: PR checks | ||
on: | ||
pull_request: | ||
branches: ['main'] | ||
jobs: | ||
check_pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- run: npm i | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Publish | ||
on: | ||
push: | ||
branches: [main] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- run: npm i | ||
- run: npm run build | ||
- name: Publish to npm | ||
uses: pascalgn/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Tests | ||
on: | ||
push: | ||
branches: ['main'] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- run: npm i | ||
- run: npm test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"semi": false, | ||
"printWidth": 155, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"bracketSpacing": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,3 @@ | ||
## A Template for a TypeScript Language Service Plugin | ||
# Adonis Typescript Plugin | ||
|
||
<img src="./docs/screenshot.png"> | ||
|
||
This repo has two projects: | ||
|
||
- `/` is a TSServer Plugin | ||
- `/example` is a TypeScript project which uses the root TSServer Plugin | ||
|
||
The source files for your project | ||
|
||
#### Get Started | ||
|
||
Get the plugin working and your TS to JS converted as you save: | ||
|
||
```ts | ||
git clone https://github.com/orta/TypeScript-TSServer-Plugin-Template | ||
cd TypeScript-TSServer-Plugin-Template | ||
|
||
# Install deps and run TypeScript | ||
npm i | ||
npx tsc --watch | ||
``` | ||
|
||
Next, get the example project up and running, it will load your TSServer Plugin from the emitted JavaScript. | ||
|
||
``` | ||
# Set up the host app to work in | ||
cd example | ||
npm i | ||
cd .. | ||
# Open one VS Code window to work on your plugin | ||
code . | ||
# Or to hook up a debugger, use this command | ||
# to have the TSServer wait till you attach: | ||
TSS_DEBUG_BRK=9559 code example | ||
# or use this to hook in later: | ||
TSS_DEBUG=9559 code example | ||
``` | ||
|
||
You can then use the launch options in this root project to connect your debugger to the running TSServer in the other window. To see changes, run the command palette "TypeScript: Reload Project" to restart the TSServer for the project. | ||
|
||
Make sure that the TypeScript version on that project runs from your `node_modules` and not the version which is embedded in vscode. You can see the logs via the vscode command 'TypeScript: Open TS Server Logs." ( search for 'Loading tsserver-plugin' to see whether it loaded correctly. ) | ||
|
||
### What Now? | ||
|
||
This project has a `debugger` statement inside the completions which will trigger on completions, you can get that running and then you have proven the toolset works and get started building your plugin. | ||
|
||
You can read up the docs on [Language Service Plugins in the TypeScript repo wiki](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin#overview-writing-a-simple-plugin). | ||
**This is still a work in progress** |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
{ | ||
"name": "my-plugin", | ||
"version": "0.0.1", | ||
"license": "MIT", | ||
"main": "./out", | ||
"dependencies": { | ||
"typescript": "^4.4.3" | ||
} | ||
"name": "adonis-ts-plugin", | ||
"version": "1.0.0-alpha.1", | ||
"license": "MIT", | ||
"main": "./out", | ||
"files": [ | ||
"out" | ||
], | ||
"scripts": { | ||
"test": "echo 'No tests yet!'", | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,14 @@ | ||
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) { | ||
const ts = modules.typescript; | ||
|
||
function create(info: ts.server.PluginCreateInfo) { | ||
// Get a list of things to remove from the completion list from the config object. | ||
// If nothing was specified, we'll just remove 'caller' | ||
const whatToRemove: string[] = info.config.remove || ["caller"]; | ||
import ts from 'typescript' | ||
import {make} from './make' | ||
import {createProxy} from './utils' | ||
|
||
// Diagnostic logging | ||
info.project.projectService.logger.info( | ||
"I'm getting set up now! Check the log for this message." | ||
); | ||
|
||
// Set up decorator object | ||
const proxy: ts.LanguageService = Object.create(null); | ||
for (let k of Object.keys(info.languageService) as Array<keyof ts.LanguageService>) { | ||
const x = info.languageService[k]!; | ||
// @ts-expect-error - JS runtime trickery which is tricky to type tersely | ||
proxy[k] = (...args: Array<{}>) => x.apply(info.languageService, args); | ||
} | ||
|
||
// Remove specified entries from completion list | ||
proxy.getCompletionsAtPosition = (fileName, position, options) => { | ||
// This is just to let you hook into something to | ||
// see the debugger working | ||
debugger | ||
type Modules = { | ||
typescript: typeof import('typescript/lib/tsserverlibrary') | ||
} | ||
|
||
const prior = info.languageService.getCompletionsAtPosition(fileName, position, options); | ||
if (!prior) return | ||
|
||
const oldLength = prior.entries.length; | ||
prior.entries = prior.entries.filter(e => whatToRemove.indexOf(e.name) < 0); | ||
|
||
// Sample logging for diagnostic purposes | ||
if (oldLength !== prior.entries.length) { | ||
const entriesRemoved = oldLength - prior.entries.length; | ||
info.project.projectService.logger.info( | ||
`Removed ${entriesRemoved} entries from the completion list` | ||
); | ||
} | ||
|
||
return prior; | ||
}; | ||
|
||
return proxy; | ||
} | ||
|
||
return { create }; | ||
export = (modules: Modules) => { | ||
const ts = modules.typescript | ||
return { | ||
create: (info: ts.server.PluginCreateInfo) => make({ts, info, service: createProxy(info.languageService), config: info.config}), | ||
} | ||
|
||
export = init; | ||
|
||
} |
Oops, something went wrong.