Skip to content

Commit

Permalink
Merge pull request #135 from swyddfa/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
alcarney authored Mar 1, 2021
2 parents 34a57b4 + 5b9c9f4 commit 0c7c0ba
Show file tree
Hide file tree
Showing 37 changed files with 747 additions and 169 deletions.
8 changes: 4 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
},
{
"label": "Grammar Tests",
"type": "shell",
"command": "npx vscode-tmgrammar-test -c -s source.rst -g rst.tmLanguage.json -g tests/python.tmLanguage.json -t \"**/*.rst\"",
"type": "npm",
"script": "test-grammar",
"group": "test",
"presentation": {
"echo": true,
Expand All @@ -67,12 +67,12 @@
"clear": false
},
"options": {
"cwd": "${workspaceRoot}/code/syntaxes"
"cwd": "${workspaceRoot}/code"
},
"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}/code/syntaxes"
"${workspaceRoot}/code"
],
"pattern": [
{
Expand Down
2 changes: 2 additions & 0 deletions code/changes/118.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Expose ``esbonio.server.logFilter`` option that can be used to limit the
components of the language server which produce output.
2 changes: 2 additions & 0 deletions code/changes/119.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The extension now makes use of the ``--cache-dir`` cli option in the language
server to set Sphinx's build output to use a known location.
2 changes: 2 additions & 0 deletions code/changes/120.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Expose ``esbonio.server.hideSphinxOutput`` option which allows for Sphinx's
build output to be omitted from the log.
1 change: 1 addition & 0 deletions code/changes/121.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that the Language Server uses the latest config options when restarted
2 changes: 2 additions & 0 deletions code/changes/122.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The extension will now automatically restart the Language Server when the
extension's configuration is updated
1 change: 1 addition & 0 deletions code/changes/123.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The extension now enforces a minimum Language Server version
1 change: 1 addition & 0 deletions code/changes/124.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed syntax highlighting of footnotes.
1 change: 1 addition & 0 deletions code/changes/125.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``css``, ``html``, ``json`` and ``yaml`` code blocks are now syntax highlighted.
2 changes: 2 additions & 0 deletions code/changes/126.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix syntax highlighting where sentences containing ellipses were incorrectly
identified as a comment
2 changes: 2 additions & 0 deletions code/changes/127.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Invalid bold text (e.g. ``** invalid**``) is no longer highlighted as valid
syntax.
2 changes: 2 additions & 0 deletions code/changes/128.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Invalid italic text (e.g. ``*invalid *``) is no longer highlighted as valid
syntax.
3 changes: 3 additions & 0 deletions code/changes/133.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
If ``esbonio.server.logLevel`` is set to ``debug`` the extension assumes the
user is working on the Language Server and will automatically open the log panel
on restarts.
2 changes: 2 additions & 0 deletions code/changes/86.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The language server's logging level is set to match the logging level defined in
the extension.
4 changes: 4 additions & 0 deletions code/changes/92.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add new ``esbonio.server.installBehavior`` option that gives greater control
over how Language Server installation is handled. ``automatic`` will install the
server in new environments without prompting, ``prompt`` will ask for
confirmation first and ``nothing`` disables installation entirely.`
2 changes: 2 additions & 0 deletions code/changes/97.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The extension now checks that the configured Python verison is compatible with
the Language Server.
2 changes: 2 additions & 0 deletions code/changes/98.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix syntax higlighting for namespaced roles (e.g. ``:py:func:``) and directives
(e.g. ``.. py:function::``)
1 change: 1 addition & 0 deletions code/changes/99.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid literals are no longer highlighted as valid syntax
35 changes: 33 additions & 2 deletions code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"test": "npm run compile-test && node ./dist/test/runTests.js",
"test-grammar": "vscode-tmgrammar-test -s source.rst -g syntaxes/rst.tmLanguage.json -g syntaxes/tests/python.tmLanguage.json -t \"syntaxes/**/*.rst\"",
"test-grammar": "vscode-tmgrammar-test -c -s source.rst -g syntaxes/rst.tmLanguage.json -g syntaxes/tests/css.tmLanguage.json -g syntaxes/tests/html.tmLanguage.json -g syntaxes/tests/json.tmLanguage.json -g syntaxes/tests/python.tmLanguage.json -g syntaxes/tests/yaml.tmLanguage.json -t \"syntaxes/**/*.rst\"",
"clean": "rm -r dist",
"deploy": "vsce publish --baseImagesUrl https://github.com/swyddfa/esbonio/raw/release/code/",
"package": "vsce package --baseImagesUrl https://github.com/swyddfa/esbonio/raw/release/code/",
Expand Down Expand Up @@ -79,7 +79,7 @@
"type": "object",
"title": "Esbonio",
"properties": {
"esbonio.log.level": {
"esbonio.server.logLevel": {
"scope": "application",
"type": "string",
"default": "error",
Expand All @@ -90,12 +90,43 @@
],
"description": "The level of log message to show in the log"
},
"esbonio.server.logFilter": {
"scope": "application",
"type": "array",
"default": null,
"items": {
"type": "string"
},
"description": "A list of logger names to limit output from"
},
"esbonio.server.pythonPath": {
"scope": "window",
"type": "string",
"default": "",
"markdownDescription": "The path to the Python interpreter to use when running the Langague Server.\n\nBy default this extension will try to use the interpreter configured via the `#python.pythonPath#` option in the Python Extension. If you do not use the Python Extension or you wish to use a different environment, then this option can be used to override the default behavior."
},
"esbonio.server.hideSphinxOutput": {
"scope": "application",
"type": "boolean",
"default": false,
"description": "Hide Sphinx build output from the Language Server log."
},
"esbonio.server.installBehavior": {
"scope": "application",
"type": "string",
"default": "prompt",
"enum": [
"nothing",
"prompt",
"automatic"
],
"enumDescriptions": [
"Don't attempt to install the Language Server if it's missing",
"Ask for confirmation before installing the Language Server",
"Never ask for confirmation, the Language Server will be installed automatically in new environments"
],
"description": "When the Language Server is missing from an environment, how should the extension handle it"
},
"esbonio.server.updateBehavior": {
"scope": "application",
"type": "string",
Expand Down
73 changes: 49 additions & 24 deletions code/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import * as semver from "semver";
import * as vscode from "vscode";
import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from "vscode-languageclient";
import { getPython, registerCommands } from "./commands";
import { LanguageClient, } from "vscode-languageclient";

import { getPython, registerCommands, UPDATE_LANGUAGE_SERVER } from "./commands";
import { LanguageServerBootstrap } from "./language-server";
import { getOutputLogger } from "./log";

export const RESTART_LANGUAGE_SERVER = 'esbonio.languageServer.restart'

const MIN_SERVER_VERSION = "0.5.0"

let bootstrap: LanguageServerBootstrap
let client: LanguageClient

export async function activate(context: vscode.ExtensionContext) {
Expand All @@ -14,32 +19,37 @@ export async function activate(context: vscode.ExtensionContext) {
logger.debug("Extension activated.")

context.subscriptions.push(vscode.commands.registerCommand(RESTART_LANGUAGE_SERVER, restartLanguageServer))
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(onConfigChanged))
registerCommands(context)

try {
let python = await getPython()
let bootstrap = new LanguageServerBootstrap(python, context)
bootstrap = new LanguageServerBootstrap(python, context)

let version = await bootstrap.ensureLanguageServer()
if (!version) {
logger.error("Language Server is not available")
return
}
logger.info(`Starting Language Server v${version}`)

let exe: Executable = {
command: python,
args: ['-m', 'esbonio']
}
let serverOptions: ServerOptions = exe
if (semver.lt(version, MIN_SERVER_VERSION)) {
let message = `Version v${version} of the Esbonio Language Server is outdated and not compatible with this
version of the extension.
Please install at least version v${MIN_SERVER_VERSION}`

let clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: 'file', language: 'rst' },
{ scheme: 'file', language: 'python' }
]
let response = await vscode.window.showErrorMessage(message, { title: "Update Server" })
if (!response || response.title !== "Update Server") {
return
}

await vscode.commands.executeCommand(UPDATE_LANGUAGE_SERVER)
version = await bootstrap.ensureLanguageServer()
}
client = new LanguageClient('esbonio', 'Esbonio Language Server', serverOptions, clientOptions)

logger.info(`Starting Language Server v${version}`)

client = bootstrap.getLanguageClient()
client.start()

} catch (err) {
Expand All @@ -54,17 +64,32 @@ export function deactivate(): Thenable<void> | undefined {
return client.stop()
}

function restartLanguageServer(): Promise<null> {
async function restartLanguageServer(): Promise<null> {
let logger = getOutputLogger();
let config = vscode.workspace.getConfiguration('esbonio')

return new Promise((resolve, reject) => {
logger.info("Stopping Language Server")
client.stop().then(_ => {
logger.info("Starting Language Server")
client.start()
resolve(null)
}).catch(err => reject(err))
})
logger.info("Stopping Language Server")
await client.stop()

client = bootstrap.getLanguageClient()
logger.info("Starting Language Server")
client.start()

// Auto open the output window when debugging to make it easier on developers :)
if (config.get<string>('server.logLevel') === 'debug') {
client.outputChannel.show()
}

return
}

function onConfigChanged(event: vscode.ConfigurationChangeEvent) {
let logger = getOutputLogger()
logger.debug("onConfigChange")

if (event.affectsConfiguration("esbonio")) {
vscode.commands.executeCommand(RESTART_LANGUAGE_SERVER)
}
}

function showError(error) {
Expand Down
Loading

0 comments on commit 0c7c0ba

Please sign in to comment.