Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Jul 18, 2024
1 parent 5959bfa commit b25173b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/js/example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
.DS_Store
.vscode
.idea
.idea
2 changes: 1 addition & 1 deletion internal/js/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ This example omits such nuances as editor integration or file system support and
* `cp $(go env GOROOT)/misc/wasm/wasm_exec.js .`
* Build gnopls as a WebAssembly file for JavaScript environment:
* `GOOS=js GOARCH=wasm make build`
* Modify paths to `wasm_exec.js` and WASM file in [worker.ts](./worker.ts) file.
* Modify paths to `wasm_exec.js` and WASM file in [worker.ts](./worker.ts) file.
2 changes: 1 addition & 1 deletion internal/js/example/src/internal/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ export const configureGoInstance = (go: Go, port: MessagePort) => {
reportFatalError(data, `failed to handle message: ${err}`)
}
}
}
}
5 changes: 3 additions & 2 deletions internal/js/example/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ const proxy = Comlink.wrap<LSPWorker>(lspWorker);
// MessagePort should be passed as a transferable object.
await proxy.connect(Comlink.transfer({ port: serverPort }, [ serverPort ]))

// Setup LSP client using a client port.
// Feel free to pick up any LSP client to library as long as it supports way to specify custom message transports.
// This example uses LSP client used by Monaco editor and VSCode.
const reader = new BrowserMessageReader(clientPort)
const writer = new BrowserMessageWriter(clientPort)

const lspClient = new MonacoLanguageClient({
const lspClient = new MonacoLanguageClient({
name: 'gnopls-lsp-client',
clientOptions: {
// use a language id as a document selector
Expand Down
12 changes: 8 additions & 4 deletions internal/js/example/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
/**
* This file contains a web worker used to host and configure LSP server.
*/

import * as Comlink from 'comlink'

import { LSPWorker } from './types';
import { configureGoInstance } from './internal/setup';

declare const self: DedicatedWorkerGlobalScope

// Copy wasm_exec.js from '$GOROOT/misc/wasm'
// Don't forget to copy wasm_exec.js from '$GOROOT/misc/wasm'
importScripts('/wasm_exec.js')

// Don't forget to build gnopls
const GNOPLS_URL = '/gnopls.wasm'

const worker: LSPWorker = {
connect: async ({ port }) => {
// Don't forget to configure filesystem before using gnopls.
// You might need to override globalThis.fs in order to provide source files for a server.
// For browsers: don't forget to configure filesystem before using gnopls!
// Override globalThis.fs with your own implementation in order to provide source files for a server.
const go = new Go()

// Feel free to pass custom environment variables and cmdline args
Expand All @@ -34,4 +38,4 @@ const worker: LSPWorker = {
},
}

Comlink.expose(worker);
Comlink.expose(worker);

0 comments on commit b25173b

Please sign in to comment.