Skip to content

Commit

Permalink
Align fountain extension to breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney authored and tombh committed Dec 1, 2022
1 parent c20c862 commit 6fbda1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions examples/fountain-extension/package-lock.json

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

5 changes: 0 additions & 5 deletions examples/fountain-extension/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
from lsprotocol.types import TEXT_DOCUMENT_COMPLETION
from lsprotocol.types import (CompletionItem, CompletionParams, CompletionList, CompletionOptions)

# The following imports are required for the glue code in 'server.ts'
import json
from pygls.protocol import deserialize_message

server = LanguageServer("foutain-language-server", "v0.1")
server.start_pyodide()

CHARACTER = re.compile(r"^[A-Z][A-Z ]+$", re.MULTILINE)

Expand Down
16 changes: 11 additions & 5 deletions examples/fountain-extension/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
importScripts("https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js")
importScripts("https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js")

/* @ts-ignore */
import * as languageServer from "./server.py";
Expand All @@ -19,25 +19,31 @@ async function initPyodide() {

/* @ts-ignore */
let pyodide = await loadPyodide({
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/"
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/"
})

console.log("Installing dependencies.")
await pyodide.loadPackage(["micropip"])
await pyodide.runPythonAsync(`
import json
import sys
import micropip
await micropip.install('pygls')
# Uncomment to use a local build of pygls
# Uncomment to use a local build of pygls -- see README for details.
# await micropip.install('https://xxx.loca.lt/out/pygls-<version>-py3-none-any.whl')
`)

console.log("Loading server.")

// Patch stdout to redirect the output.
pyodide.globals.get('sys').stdout.write = patchedStdout
await pyodide.runPythonAsync(languageServer)
await pyodide.runPythonAsync(`
${languageServer}
server.start_pyodide()
`)

return pyodide
}
Expand All @@ -55,7 +61,7 @@ onmessage = async (event) => {
await pyodide.runPythonAsync(`
from js import client_message
message = json.loads(client_message, object_hook=deserialize_message)
message = json.loads(client_message, object_hook=server.lsp._deserialize_message)
server.lsp._procedure_handler(message)
`)
}

0 comments on commit 6fbda1c

Please sign in to comment.