-
Notifications
You must be signed in to change notification settings - Fork 4
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 #4 from x1unix/feat/support-wasm
feat: introduce connector for js/wasm
- Loading branch information
Showing
18 changed files
with
817 additions
and
8 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
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,12 @@ | ||
package env | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"github.com/gnolang/gnopls/internal/js" | ||
) | ||
|
||
func GetConnection(ctx context.Context) (net.Conn, error) { | ||
return js.DialHost(ctx) | ||
} |
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,15 @@ | ||
//go:build !js | ||
|
||
package env | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"os" | ||
|
||
"go.lsp.dev/pkg/fakenet" | ||
) | ||
|
||
func GetConnection(_ context.Context) (net.Conn, error) { | ||
return fakenet.NewConn("stdio", os.Stdin, os.Stdout), nil | ||
} |
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,22 @@ | ||
// Package js provides primitives to integrate language server with javascript environments such as browsers and Node. | ||
package js | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"go.lsp.dev/pkg/fakenet" | ||
) | ||
|
||
// DialHost registers LSP message listener in JavaScript host and returns connection to use by LSP server. | ||
// | ||
// This function should be called only once before starting LSP server. | ||
func DialHost(ctx context.Context) (net.Conn, error) { | ||
reader, err := registerRequestListener(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
conn := fakenet.NewConn("js", reader, messageWriter) | ||
return conn, nil | ||
} |
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,4 @@ | ||
node_modules | ||
.DS_Store | ||
.vscode | ||
.idea |
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 @@ | ||
# Gnopls Embedding Example | ||
|
||
This directory contains a bare-minimum code to integrate Gnopls as a WebAssembly module | ||
into browser or Node.js environment. | ||
|
||
This example omits such nuances as editor integration or file system support and focuses just on basics. | ||
|
||
## Prerequisites | ||
|
||
* Copy `wasm_exec.js` file using following command: | ||
* `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. |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@types/golang-wasm-exec": "^1.15.2", | ||
"comlink": "^4.4.1", | ||
"monaco-languageclient": "^8.7.0", | ||
"vscode-languageclient": "^9.0.1", | ||
"vscode-languageserver-protocol": "^3.17.5" | ||
} | ||
} |
Oops, something went wrong.