asciidoctor / asciidoctor-vscode

AsciiDoc support for Visual Studio Code using Asciidoctor
Other
336 stars 97 forks source link

Path handling problem on Windows #902

Open ahy-peter-zumtobel opened 1 month ago

ahy-peter-zumtobel commented 1 month ago

Summary:

Newer versions of the extension have a bug in the path handling.

Description:

The value of the variable (path) {asciidoctorconfigdir} starts with a slash (example: '/c:/') so derived path can't be resolved.

Version: since 3.1.6

Environment: Version: 1.93.0 (user setup) Commit: 4849ca9bdf9666755eb463db297b69e5385090e3 Date: 2024-09-04T13:02:38.431Z Electron: 30.4.0 ElectronBuildId: 10073054 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.22631

Reproduce:

  1. Create the files '.asciidoctorconfig.adoc'
  2. Create 'foo.adoc' with following content: {asciidoctorconfigdir}
  3. Look at the preview window. Path is shown as '/c:/...'

Screenshot from 2024-09-12 15-24-35

Related issues

Hints

Suspected corrupt file: asciidoctor-vscode/src/features/AsciidoctorConfig.ts

Suspected corrupt line of code: 72: const asciidoctorConfigParentDirectory = asciidoctorConfig.path.slice(0, asciidoctorConfig.path.lastIndexOf('/')) -> ".path" delivers '/c:/' on Windows.

Temporary workaround: Use version v3.1.5

Possible solution

For this specific case it would be sufficient to replace const asciidoctorConfigParentDirectory = asciidoctorConfig.path.slice(0, asciidoctorConfig.path.lastIndexOf('/')) with const asciidoctorConfigParentDirectory = dir(asciidoctorConfig, workspaceFolderUri).fsPath

This has the intended behavior on Windows as well as on Linux. But I suspect a general path handling problem to be the root cause.

ggrossetie commented 1 month ago

.path is the URI and /C:/path/to/directory is a valid URI. The Window file explorer should be able to navigate to file:///C:/path/to/directory/file.txt.

Having said that, we might want to use fsPath (which is not available in VS web) instead of path. Maybe it would be safer to use fsPath only if we are not in a web environment.