diff --git a/code/changes/340.fix.rst b/code/changes/340.fix.rst new file mode 100644 index 00000000..6cac3451 --- /dev/null +++ b/code/changes/340.fix.rst @@ -0,0 +1 @@ +Fix handling of Windows URIs in preview code. diff --git a/code/src/constants.ts b/code/src/constants.ts index 9c063099..0912c3a9 100644 --- a/code/src/constants.ts +++ b/code/src/constants.ts @@ -3,7 +3,7 @@ export const PYTHON_EXTENSION = "ms-python.python" export namespace Server { export const REQUIRED_PYTHON = "3.6.0" - export const REQUIRED_VERSION = "0.9.0" + export const REQUIRED_VERSION = "0.10.2" } export namespace Commands { diff --git a/code/src/preview/view.ts b/code/src/preview/view.ts index fb157fae..878fc489 100644 --- a/code/src/preview/view.ts +++ b/code/src/preview/view.ts @@ -121,13 +121,13 @@ export class PreviewManager { let buildDir = config.buildDir let sourceUri = editor.document.uri - if (sourceUri.scheme !== 'file' || !sourceUri.path.startsWith(srcDir)) { + if (sourceUri.scheme !== 'file' || !sourceUri.fsPath.startsWith(srcDir)) { this.logger.debug(`Ignoring ${sourceUri}`) return undefined } - let rstPath = sourceUri.path.replace(srcDir, '') + let rstPath = sourceUri.fsPath.replace(srcDir, '') let htmlPath = rstPath.replace(new RegExp(`\\${path.extname(rstPath)}`), '.html') // Check if the file exists. diff --git a/lib/esbonio/.bumpversion.cfg b/lib/esbonio/.bumpversion.cfg index 78f8fe5a..aabb1792 100644 --- a/lib/esbonio/.bumpversion.cfg +++ b/lib/esbonio/.bumpversion.cfg @@ -3,7 +3,7 @@ current_version = 0.10.1 commit = False tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(.dev(?P\d+))? -serialize = +serialize = {major}.{minor}.{patch}.dev{dev} {major}.{minor}.{patch} diff --git a/lib/esbonio/changes/341.fix.rst b/lib/esbonio/changes/341.fix.rst new file mode 100644 index 00000000..09f44112 --- /dev/null +++ b/lib/esbonio/changes/341.fix.rst @@ -0,0 +1 @@ +Previews on Windows should now start correctly diff --git a/lib/esbonio/esbonio/lsp/sphinx/__init__.py b/lib/esbonio/esbonio/lsp/sphinx/__init__.py index 580f1101..149e6c9c 100644 --- a/lib/esbonio/esbonio/lsp/sphinx/__init__.py +++ b/lib/esbonio/esbonio/lsp/sphinx/__init__.py @@ -5,6 +5,7 @@ import traceback import typing from multiprocessing import Process +from multiprocessing import Queue from typing import Any from typing import Dict from typing import Iterator @@ -40,6 +41,7 @@ from esbonio.lsp.rst import RstLanguageServer from esbonio.lsp.rst import ServerConfig from esbonio.lsp.sphinx.preview import make_preview_server +from esbonio.lsp.sphinx.preview import start_preview_server try: from sphinx.util.logging import OnceFilter @@ -478,7 +480,7 @@ def preview(self, options: Dict[str, Any]) -> Dict[str, Any]: return {} - if not self.preview_process: + if not self.preview_process and not IS_WIN: self.logger.debug("Starting preview server.") server = make_preview_server(self.app.outdir) self.preview_port = server.server_port @@ -486,6 +488,16 @@ def preview(self, options: Dict[str, Any]) -> Dict[str, Any]: self.preview_process = Process(target=server.serve_forever, daemon=True) self.preview_process.start() + if not self.preview_process and IS_WIN: + self.logger.debug("Starting preview server") + + q: Queue = Queue() + self.preview_process = Process( + target=start_preview_server, args=(q, self.app.outdir), daemon=True + ) + self.preview_process.start() + self.preview_port = q.get() + if options.get("show", True): self.show_document( ShowDocumentParams( diff --git a/lib/esbonio/esbonio/lsp/sphinx/preview.py b/lib/esbonio/esbonio/lsp/sphinx/preview.py index fbf76ee7..dbdd84f9 100644 --- a/lib/esbonio/esbonio/lsp/sphinx/preview.py +++ b/lib/esbonio/esbonio/lsp/sphinx/preview.py @@ -2,6 +2,7 @@ from functools import partial from http.server import HTTPServer from http.server import SimpleHTTPRequestHandler +from multiprocessing import Queue from typing import Any from typing import Type @@ -25,3 +26,16 @@ def make_preview_server(directory: str) -> HTTPServer: """Construst a http server that can be used to preview the docs.""" handler_class = partial(RequestHandler, directory=directory) return ServerClass(("localhost", 0), handler_class) + + +def start_preview_server(q: Queue, directory: str): + """Start a preview server in the given directory. + + The server's port number will be sent back via the given ``q`` object. + """ + + handler_class = partial(RequestHandler, directory=directory) + server = ServerClass(("localhost", 0), handler_class) + q.put(server.server_port) + + server.serve_forever()