Skip to content

Commit

Permalink
Merge pull request #1 from webNeat/develop
Browse files Browse the repository at this point in the history
Alpha version
  • Loading branch information
webNeat authored Jan 29, 2024
2 parents 3b8ca80 + f505e16 commit 53caf2f
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 266 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pr.yml
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
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
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 }}
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
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
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": false,
"printWidth": 155,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false
}
53 changes: 2 additions & 51 deletions README.md
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 removed docs/screenshot.png
Binary file not shown.
3 changes: 0 additions & 3 deletions example/.vscode/settings.json

This file was deleted.

5 changes: 0 additions & 5 deletions example/index.ts

This file was deleted.

18 changes: 0 additions & 18 deletions example/package-lock.json

This file was deleted.

7 changes: 0 additions & 7 deletions example/package.json

This file was deleted.

107 changes: 0 additions & 107 deletions example/tsconfig.json

This file was deleted.

35 changes: 25 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions package.json
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"
}
}
60 changes: 11 additions & 49 deletions src/index.ts
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;

}
Loading

0 comments on commit 53caf2f

Please sign in to comment.