Compare commits
35 Commits
Author | SHA1 | Date |
---|---|---|
CismonX | ed968839b6 | |
CismonX | f8bcf86fb1 | |
CismonX | 8f289fbcb8 | |
CismonX | afe3694a88 | |
CismonX | 530902128c | |
CismonX | 1294764698 | |
CismonX | 9de1ba26b0 | |
CismonX | 13feb8a1f4 | |
CismonX | ad685014d2 | |
CismonX | 3f8c23d917 | |
CismonX | 3b3478decb | |
CismonX | a5837defce | |
CismonX | 5e86022e32 | |
CismonX | 229d84bd2d | |
CismonX | c3e33c3340 | |
CismonX | 2275b94c1d | |
CismonX | 7820db6955 | |
CismonX | 26c8d32129 | |
CismonX | c111ec89a0 | |
CismonX | 3896bf44db | |
CismonX | d165537d60 | |
CismonX | 1707ece4bc | |
CismonX | f5c8ae309c | |
CismonX | 2fd2a025c3 | |
CismonX | 84a5c506fe | |
CismonX | 2004131b6c | |
CismonX | 3ecb2a5b03 | |
CismonX | b3b9644af0 | |
CismonX | 1b80cb315d | |
CismonX | c0f0fd2ea5 | |
CismonX | 829a35679e | |
CismonX | 96ae0b8f24 | |
CismonX | 4145c8a64f | |
CismonX | 6cff7138f0 | |
CismonX | 1dbafb6c97 |
|
@ -6,6 +6,7 @@
|
|||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
*.asc
|
||||
*.vsix
|
||||
.vscode/
|
||||
node_modules/
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
**/*.map
|
||||
**/*.ts
|
||||
.drone.yml
|
||||
.woodpecker.yml
|
||||
.gitignore
|
||||
.gitattributes
|
||||
.travis.yml
|
||||
|
|
|
@ -6,12 +6,16 @@
|
|||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
# For history build logs,
|
||||
# see <https://ci.cismon.net/repos/cismonx/vscode-texinfo>.
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: node:14.16
|
||||
image: node:18-alpine
|
||||
when:
|
||||
- event: [push, tag, manual]
|
||||
branch: primary
|
||||
commands:
|
||||
- npm --unsafe-perm ci
|
||||
- apk add --no-cache perl unzip
|
||||
- npm ci
|
||||
- npm run package
|
28
CHANGELOG.md
28
CHANGELOG.md
|
@ -1,13 +1,31 @@
|
|||
<!--
|
||||
Copyright (C) 2020,2021 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
Copyright (C) 2020,2021,2022,2024 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
-->
|
||||
|
||||
# Changelog
|
||||
|
||||
## v0.3.0 - 04/04/2024
|
||||
|
||||
* Add configuration for customization variables (`makeinfo -c KEY=VAL`).
|
||||
* Support GNU Texinfo 7.1.
|
||||
|
||||
## v0.2.4 - 02/02/2022
|
||||
|
||||
* Fix a bug which breaks the snippet completion of block commands.
|
||||
|
||||
## v0.2.3 - 10/23/2021
|
||||
|
||||
* Fix a bug which prevents diagnostic info from displaying correctly in GNU Texinfo 6.8, and on Windows platform.
|
||||
|
||||
## v0.2.2 - 10/03/2021
|
||||
|
||||
* Fix a bug which breaks configuration `preview.includePaths` on Windows.
|
||||
* Remove completion for commands which are deprecated in GNU Texinfo 6.8.
|
||||
|
||||
## v0.2.1 - 05/05/2021
|
||||
|
||||
* Fix an error in build script which produces corrupted metadata in `.vsix` package.
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<!--
|
||||
Copyright (C) 2021 CismonX <admin@cismon.net>
|
||||
Copyright (C) 2021 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
-->
|
||||
|
||||
# License Notice
|
||||
|
@ -13,34 +13,32 @@ this notice are preserved. This file is offered as-is, without any warranty.
|
|||
Project files listed below cannot carry a license notice by themselves, due to
|
||||
file format restrictions.
|
||||
|
||||
```text
|
||||
assets/texinfo.png
|
||||
```
|
||||
assets/texinfo.png
|
||||
|
||||
They should be treated as if they each contains the following text:
|
||||
|
||||
```text
|
||||
Copyright (C) 2020,2021 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
```
|
||||
This file is released into the public domain using [CC0].
|
||||
|
||||
## Files from other projects
|
||||
|
||||
Source code from the projects listed below are **not** part of vscode-texinfo.
|
||||
Source code from the projects listed below are *not* part of vscode-texinfo.
|
||||
However, when building the project, they are downloaded, compiled, and packaged
|
||||
into a single binary file alongside with vscode-texinfo.
|
||||
|
||||
| Project | Copyright Holder | License |
|
||||
| - | - | - |
|
||||
| [Texinfo syntax highlighting](https://github.com/Alhadis/language-texinfo) | John Gardner | [ISC](https://github.com/Alhadis/language-texinfo/blob/master/LICENSE.md) |
|
||||
| Project | Copyright Holder | License |
|
||||
| - | - | - |
|
||||
| [Texinfo syntax highlighting] | John Gardner | [ISC](https://github.com/Alhadis/language-texinfo/blob/master/LICENSE.md) |
|
||||
|
||||
The following projects are required during runtime of vscode-texinfo, but as
|
||||
separate programs.
|
||||
|
||||
| Project | Copyright Holder | License |
|
||||
| - | - | - |
|
||||
| [Visual Studio Code](https://github.com/microsoft/vscode) | Microsoft Corporation | [MIT](https://github.com/microsoft/vscode/blob/main/LICENSE.txt) |
|
||||
| [GNU Texinfo](https://www.gnu.org/software/texinfo) | Free Software Foundation | [GPL-3.0](https://git.savannah.gnu.org/cgit/texinfo.git/tree/COPYING)-or-later |
|
||||
| Project | Copyright Holder | License |
|
||||
| - | - | - |
|
||||
| [Visual Studio Code] | Microsoft Corporation | [MIT](https://github.com/microsoft/vscode/blob/main/LICENSE.txt) |
|
||||
| [GNU Texinfo] | Free Software Foundation | [GPL-3.0](https://git.savannah.gnu.org/cgit/texinfo.git/tree/COPYING)-or-later |
|
||||
|
||||
|
||||
<!-- Reference Links -->
|
||||
|
||||
[CC0]: https://creativecommons.org/public-domain/cc0/
|
||||
[Texinfo syntax highlighting]: https://github.com/Alhadis/language-texinfo
|
||||
[Visual Studio Code]: https://github.com/microsoft/vscode
|
||||
[GNU Texinfo]: https://www.gnu.org/software/texinfo
|
||||
|
|
27
README.md
27
README.md
|
@ -1,21 +1,20 @@
|
|||
<!--
|
||||
Copyright (C) 2020,2021 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
Copyright (C) 2020,2021,2024 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
-->
|
||||
|
||||
# vscode-texinfo
|
||||
|
||||
[![Build Status](https://shields.io/drone/build/CismonX/vscode-texinfo?server=https%3A%2F%2Fdrone.cismon.net)](https://drone.cismon.net/CismonX/vscode-texinfo)
|
||||
[![License](https://img.shields.io/badge/license-GPL--3.0--or--later-blue.svg)](LICENSE)
|
||||
[![License]](LICENSE)
|
||||
|
||||
## About
|
||||
|
||||
vscode-texinfo is an extension of Visual Studio Code which aims at improving user experience for editing Texinfo documents.
|
||||
vscode-texinfo is an extension of [Visual Studio Code] which provides the
|
||||
following features for editing [Texinfo] documents:
|
||||
|
||||
Major features include:
|
||||
* Syntax Highlighting
|
||||
* Code Completion
|
||||
* HTML Preview
|
||||
|
@ -25,4 +24,12 @@ Major features include:
|
|||
|
||||
## Getting Started
|
||||
|
||||
For instructions about how to install, use, and contribute to vscode-texinfo, see the [online user manual](https://nongnu.org/vscode-texinfo/manual).
|
||||
For instructions on how to install, use, and contribute to vscode-texinfo,
|
||||
see the [user manual].
|
||||
|
||||
<!-- Reference Links -->
|
||||
|
||||
[Visual Studio Code]: https://github.com/microsoft/vscode
|
||||
[Texinfo]: https://www.gnu.org/software/texinfo/
|
||||
[License]: https://img.shields.io/badge/license-GPL--3.0--or--later-blue.svg
|
||||
[user manual]: https://nongnu.org/vscode-texinfo/manual
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
@set vscode-docs-url https://code.visualstudio.com/docs
|
||||
@set vscode-api-url https://code.visualstudio.com/api
|
||||
@set gnu-texinfo-docs https://www.gnu.org/software/texinfo/manual/texinfo
|
||||
@set sv-home-url https://sv.nongnu.org
|
||||
@set sv-releases-url https://dl.sv.nongnu.org/releases
|
||||
|
||||
@tex
|
||||
\global\def\linkcolor{0 0 1}
|
||||
|
@ -20,7 +22,7 @@
|
|||
This manual is for vscode-texinfo (version @value{VERSION}), an extension of
|
||||
Visual Studio Code.
|
||||
|
||||
Copyright @copyright{} 2021 CismonX <admin@@cismon.net>
|
||||
Copyright @copyright{} 2021,2024 CismonX <admin@@cismon.net>
|
||||
|
||||
@quotation
|
||||
This manual is licensed under a
|
||||
|
@ -51,7 +53,7 @@ Creative Commons Attribution-ShareAlike 4.0 International License}.
|
|||
This manual is for vscode-texinfo (version @value{VERSION}), an extension of
|
||||
Visual Studio Code.
|
||||
|
||||
Copyright @copyright{} 2021 CismonX <admin@@cismon.net>
|
||||
Copyright @copyright{} 2021,2024 CismonX <admin@@cismon.net>
|
||||
|
||||
This manual is licensed under a
|
||||
@url{https://creativecommons.org/licenses/by-sa/4.0/,
|
||||
|
@ -72,8 +74,8 @@ Creative Commons Attribution-ShareAlike 4.0 International License}.
|
|||
@chapter Overview
|
||||
|
||||
Texinfo is a typesetting language designed for writing software manuals. It's
|
||||
the official documention format for GNU projects, but not as popular in modern
|
||||
non-GNU free software projects.
|
||||
the official documentation format for GNU projects, but not as popular in
|
||||
modern non-GNU free software projects.
|
||||
|
||||
One of the main reasons is the lack of editor support. While Emacs does offer a
|
||||
``texinfo-mode'', however, Emacs is not widely used among average software
|
||||
|
@ -81,10 +83,10 @@ developers.
|
|||
|
||||
We believe that Texinfo deserves more users, for it is an excellent format for
|
||||
writing software manuals, as well as other technical materials. We chose Visual
|
||||
Studio Code, one of the most popular code editors as of year 2020, and developed
|
||||
this very extension, vscode-texinfo, which provides some useful features for
|
||||
Visual Studio Code regarding the Texinfo format, in the hope that more
|
||||
developers can benefit from it.
|
||||
Studio Code, one of the most popular code editors as of year 2020, and
|
||||
developed this very extension, vscode-texinfo, which provides some useful
|
||||
features for Visual Studio Code regarding the Texinfo format, in the hope that
|
||||
more developers can benefit from it.
|
||||
|
||||
vscode-texinfo is free software. You can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -99,11 +101,11 @@ version 3 of the License}, or (at your option) any later version.
|
|||
@node Contributing
|
||||
@section Contributing
|
||||
|
||||
This project is hosted on @url{https://sv.gnu.org/p/vscode-texinfo, Savannah}.
|
||||
Any kind of contribution is welcome, including bug reports, patches, and general
|
||||
discussions regarding the usage of vscode-texinfo.
|
||||
This project is hosted on @url{@value{sv-home-url}/p/vscode-texinfo, Savannah}.
|
||||
Any kind of contribution is welcome, including bug reports, patches, and
|
||||
general discussions regarding the usage of vscode-texinfo.
|
||||
|
||||
Before you submit something, please make sure that you have read this manual,
|
||||
Before you post something, please make sure that you have read this manual,
|
||||
and no one else has posted the same content.
|
||||
|
||||
|
||||
|
@ -120,7 +122,7 @@ binary release, which is proprietary software. You can also build it from
|
|||
|
||||
@quotation Note
|
||||
Theoretically vscode-texinfo can work with any version of Visual Studio Code
|
||||
since 1.40, but not all versions are tested. It's recommended to install a
|
||||
since 1.82, but not all versions are tested. It's recommended to install a
|
||||
latest release.
|
||||
@end quotation
|
||||
|
||||
|
@ -139,35 +141,21 @@ and you can find and install this extension (Extension ID:
|
|||
@section Manual Installation
|
||||
|
||||
You can manually download the @code{.vsix} file, from either Savannah's
|
||||
@url{https://dl.sv.gnu.org/releases/vscode-texinfo/, download area},
|
||||
@url{@value{sv-releases-url}/vscode-texinfo/, download area},
|
||||
@url{https://open-vsx.org/extension/CismonX/texinfo, Open VSX Registry}, or the
|
||||
proprietary Visual Studio Marketplace.
|
||||
|
||||
Before you install a @code{.vsix} file downloaded from a third party,
|
||||
you should check whether the file matches a trusted signature:
|
||||
|
||||
@ifhtml
|
||||
@set vsix-name texinfo-@value{VERSION}.vsix
|
||||
|
||||
@example
|
||||
wget -O cismonx.gpg.asc "https://sv.gnu.org/people/viewgpg.php?user_id=214244"
|
||||
gpg --import cismonx.gpg.asc
|
||||
|
||||
wget https://dl.sv.gnu.org/releases/vscode-texinfo/texinfo-0.2.0.vsix.sig.asc
|
||||
gpg --verify texinfo-0.2.0.vsix.sig.asc texinfo-0.2.0.vsix
|
||||
wget -O- '@value{sv-home-url}/people/viewgpg.php?user_id=214244' \
|
||||
| gpg --import
|
||||
wget -O- @value{sv-releases-url}/vscode-texinfo/@value{vsix-name}.sig.asc \
|
||||
| gpg --verify - @value{vsix-name}
|
||||
@end example
|
||||
@end ifhtml
|
||||
|
||||
@ifnothtml
|
||||
@example
|
||||
wget -O cismonx.gpg.asc \
|
||||
"https://sv.gnu.org/people/viewgpg.php?user_id=214244"
|
||||
gpg --import cismonx.gpg.asc
|
||||
|
||||
wget "https://dl.sv.gnu.org/releases/vscode-texinfo/
|
||||
texinfo-0.2.0.vsix.sig.asc"
|
||||
gpg --verify texinfo-0.2.0.vsix.sig.asc texinfo-0.2.0.vsix
|
||||
@end example
|
||||
@end ifnothtml
|
||||
|
||||
|
||||
Finally, install the @code{.vsix} file to Visual Studio Code via command
|
||||
palette: @code{Extensions: Install from VSIX...}.
|
||||
|
@ -176,7 +164,7 @@ palette: @code{Extensions: Install from VSIX...}.
|
|||
@node Build from Source
|
||||
@section Build from Source
|
||||
|
||||
You can generate the @code{.vsix} file from the source code of vscode-texinfo.
|
||||
The @code{.vsix} file can be built from the source code of vscode-texinfo.
|
||||
|
||||
First, clone the source code repository:
|
||||
|
||||
|
@ -223,8 +211,8 @@ suffix @code{.texi}, @code{.txi} or @code{.texinfo}, this process should be
|
|||
automatic. If not, find and click the status bar item with ``Select Language
|
||||
Mode'' tooltip, then choose ``Texinfo'' in the menu which just popped up.
|
||||
|
||||
If syntax highlighting does not look satisfactory, try another color theme where
|
||||
keyword/operator colors are distinct. Some good examples are Solarized
|
||||
If syntax highlighting does not look satisfactory, try another color theme
|
||||
where keyword/operator colors are distinct. Some good examples are Solarized
|
||||
Light/Dark, Monokai, etc.
|
||||
|
||||
For details about how to @url{@value{vscode-docs-url}
|
||||
|
@ -265,10 +253,10 @@ code snippets is disabled by default. You can re-enable it on by switching off
|
|||
|
||||
@quotation Note
|
||||
Code completion provided by vscode-texinfo does not recognize much of Texinfo's
|
||||
semantics, and completion may appear in contexts where it should not exist. This
|
||||
is a known bug (which cannot be fixed in near future, unless a
|
||||
@url{https://microsoft.github.io/language-server-protocol/, language server} for
|
||||
Texinfo is implemented, which is not trivial).
|
||||
semantics, and completion may appear in contexts where it should not exist.
|
||||
This is a known bug (which cannot be fixed in near future, unless a
|
||||
@url{https://microsoft.github.io/language-server-protocol/, language server}
|
||||
for Texinfo is implemented, which is not trivial).
|
||||
@end quotation
|
||||
|
||||
|
||||
|
@ -286,14 +274,15 @@ Three types of code blocks can be recognized by vscode-texinfo:
|
|||
@item Consecutive lines of comments
|
||||
@end itemize
|
||||
|
||||
While editing a Texinfo document, you can collapse or expand a code block either
|
||||
by clicking the folding icon to the left of the first line of the block, or by
|
||||
invoking a corresponding command. See the Visual Studio Code User Guide for
|
||||
@url{@value{vscode-docs-url}/editor/codebasics#_folding, details}.
|
||||
While editing a Texinfo document, you can collapse or expand a code block
|
||||
either by clicking the folding icon to the left of the first line of the block,
|
||||
or by invoking a corresponding command. See the Visual Studio Code User Guide
|
||||
for @url{@value{vscode-docs-url}/editor/codebasics#_folding, details}.
|
||||
|
||||
@quotation Note
|
||||
Due to performance issues, the block hierarchy of a Texinfo document is
|
||||
re-calculated only when total line count changes, or when the document is saved.
|
||||
re-calculated only when total line count changes, or when the document is
|
||||
saved.
|
||||
@end quotation
|
||||
|
||||
|
||||
|
@ -314,10 +303,10 @@ See the Visual Studio Code User Guide for more information about
|
|||
Some more advanced features of vscode-texinfo is available if GNU Texinfo is
|
||||
correctly installed and configured on your device.
|
||||
|
||||
@url{https://www.gnu.org/software/texinfo, GNU Texinfo} is the official (and the
|
||||
only known) full implementation of Texinfo. On most platforms, it can be easily
|
||||
installed using a package manager. For example, if you're using a Debian-based
|
||||
GNU/Linux distribution, you can install GNU Texinfo with:
|
||||
@url{https://www.gnu.org/software/texinfo, GNU Texinfo} is the official (and
|
||||
the only known) full implementation of Texinfo. On most platforms, it can be
|
||||
easily installed using a package manager. For example, if you're using a
|
||||
Debian-based GNU/Linux distribution, you can install GNU Texinfo with:
|
||||
|
||||
@example
|
||||
sudo apt-get install texinfo
|
||||
|
@ -329,8 +318,8 @@ plain text, etc.
|
|||
|
||||
To specify the location of @code{makeinfo}, edit the configuration item
|
||||
@code{texinfo.makeinfo}. If it's not located in @code{$PATH}, an absolute path
|
||||
should be specified. Also note that the path should not contain any command line
|
||||
arguments.
|
||||
should be specified. Also note that the path should not contain any command
|
||||
line arguments.
|
||||
|
||||
To check whether GNU Texinfo is correctly installed and configured, see
|
||||
@ref{Version Indicator}.
|
||||
|
@ -346,20 +335,20 @@ To check whether GNU Texinfo is correctly installed and configured, see
|
|||
@section Version Indicator
|
||||
|
||||
The version indicator is a status bar item with text ``GNU Texinfo''. It is
|
||||
located on the right side of the status bar, which is shown when the active text
|
||||
editor contains a Texinfo document.
|
||||
located on the right side of the status bar, which is shown when the active
|
||||
text editor contains a Texinfo document.
|
||||
|
||||
If you see a @b{check icon} and the version of GNU Texinfo, then
|
||||
congratulations, you're all set. If a @b{cross icon} is displayed, it means
|
||||
that GNU Texinfo is @emph{not} correctly installed and configured.
|
||||
|
||||
If a @b{warning icon} is displayed, it means that the currently installed GNU
|
||||
Texinfo is outdated, or has an unrecognizable version number. In that case, some
|
||||
features may not work as expected.
|
||||
Texinfo is outdated, or has an unrecognizable version number. In that case,
|
||||
some features may not work as expected.
|
||||
|
||||
@quotation Note
|
||||
The version indicator does not automatically refresh since the activation of the
|
||||
extension. To manually trigger a refresh, click the status bar item.
|
||||
The version indicator does not automatically refresh since the activation of
|
||||
the extension. To manually trigger a refresh, click the status bar item.
|
||||
@end quotation
|
||||
|
||||
|
||||
|
@ -367,13 +356,13 @@ extension. To manually trigger a refresh, click the status bar item.
|
|||
@section HTML Preview
|
||||
|
||||
You can generate the HTML preview of a Texinfo document in Visual Studio Code,
|
||||
to see how the document looks like when displayed online.
|
||||
to see how the document looks like when displayed in a web browser.
|
||||
|
||||
In the active text editor which contains a Texinfo document, click the ``Show
|
||||
Preview'' button on the top right of the editor. A webview will be created in a
|
||||
split editor (if not already), and the HTML preview will be displayed there. The
|
||||
``Show Preview'' command is also available in command palette, and has a default
|
||||
@code{Ctrl+K V} key binding (on GNU/Linux).
|
||||
split editor (if not already), and the HTML preview will be displayed there.
|
||||
The ``Show Preview'' command is also available in command palette, and has a
|
||||
default @code{Ctrl+K V} key binding (on GNU/Linux).
|
||||
|
||||
The HTML used for preview is generated by @code{makeinfo --html --nosplit}, and
|
||||
Texinfo source is read from disk, instead of taken from a
|
||||
|
@ -402,11 +391,12 @@ means that the preview is being updated.
|
|||
|
||||
You can use a custom CSS to make the HTML preview look prettier. To configure
|
||||
this, edit the configuration option @code{texinfo.preview.customCSS}. The CSS
|
||||
file can either be an online or a local (starting with @code{file://}) resource.
|
||||
file can either be an online or a local (starting with @code{file://})
|
||||
resource.
|
||||
|
||||
A good example is @url{https://www.gnu.org/software/gnulib/manual.css}, which is
|
||||
popular among manuals of GNU projects. (Note: May require some tinkering when
|
||||
used with darker editor themes)
|
||||
A good example is @url{https://www.gnu.org/software/gnulib/manual.css}, which
|
||||
is popular among manuals of GNU projects. (Note: May require some tinkering
|
||||
when used with darker editor themes)
|
||||
|
||||
|
||||
@node Goto Node
|
||||
|
@ -423,7 +413,7 @@ allow @@-commands}, which is not handled in vscode-texinfo due to performance
|
|||
considerations. For these nodes, this feature does not work.
|
||||
@end quotation
|
||||
|
||||
To disable this feature and hide the code lenses, switch off the configuation
|
||||
To disable this feature and hide the code lenses, switch off the configuration
|
||||
item @code{texinfo.enableCodeLens}.
|
||||
|
||||
See the Visual Studio Code User Guide for more information about
|
||||
|
@ -441,7 +431,7 @@ HTML previews.
|
|||
can produce before quitting. (@code{--error-limit=NUM})
|
||||
@item @code{texinfo.preview.includePaths}: Array of extra paths to search for
|
||||
@code{@@include} files. (@code{-I PATH})
|
||||
@item @code{texinfo.preview.maxSize}: Max allowed size for the genereated HTML
|
||||
@item @code{texinfo.preview.maxSize}: Max allowed size for the generated HTML
|
||||
file before it's displayed in the preview. Files larger than this limit will
|
||||
trigger an error.
|
||||
@item @code{texinfo.preview.noHeaders}: When enabled, headers and menus are no
|
||||
|
@ -453,6 +443,8 @@ are not validated. (@code{--no-validate})
|
|||
@item @code{texinfo.preview.variables}: Array of variables to define (as with
|
||||
@code{@@set}). If a variable has a value, use the ASCII space character to
|
||||
separate key and value.
|
||||
@item @code{texinfo.preview.customizationVariables}: Array of customization
|
||||
variables. (@code{-c KEY=VALUE})
|
||||
@end itemize
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
57
package.json
57
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"_copyrightNotice": [
|
||||
"Copyright (C) 2020,2021 CismonX <admin@cismon.net>",
|
||||
"Copyright (C) 2020,2021,2022,2024 CismonX <admin@cismon.net>",
|
||||
"Copying and distribution of this file, with or without modification,",
|
||||
"are permitted in any medium without royalty, provided the copyright notice and this notice are preserved.",
|
||||
"This file is offered as-is, without any warranty."
|
||||
|
@ -9,38 +9,37 @@
|
|||
"displayName": "Texinfo Language Support",
|
||||
"description": "Texinfo language support for Visual Studio Code",
|
||||
"publisher": "cismonx",
|
||||
"version": "0.2.1",
|
||||
"version": "0.3.0",
|
||||
"author": {
|
||||
"name": "CismonX",
|
||||
"email": "admin@cismon.net",
|
||||
"url": "https://cismon.net"
|
||||
},
|
||||
"license": "GPL-3.0-or-later",
|
||||
"homepage": "https://sv.gnu.org/p/vscode-texinfo",
|
||||
"homepage": "https://savannah.nongnu.org/p/vscode-texinfo",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.sv.gnu.org/cgit/vscode-texinfo.git"
|
||||
"url": "https://git.savannah.nongnu.org/cgit/vscode-texinfo.git"
|
||||
},
|
||||
"icon": "assets/texinfo.png",
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.43",
|
||||
"@types/terser-webpack-plugin": "^5.0.3",
|
||||
"@types/vscode": "~1.40.0",
|
||||
"@types/webpack": "^5.28.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.22.1",
|
||||
"@typescript-eslint/parser": "^4.22.1",
|
||||
"cson": "^7.20.0",
|
||||
"eslint": "^7.25.0",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/vscode": "~1.82.0",
|
||||
"@types/webpack": "^5.28.5",
|
||||
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
||||
"@typescript-eslint/parser": "^7.5.0",
|
||||
"@vscode/vsce": "^2.24.0",
|
||||
"cson": "^8.4.0",
|
||||
"eslint": "^8.57.0",
|
||||
"json": "^11.0.0",
|
||||
"json5": "^2.2.0",
|
||||
"language-texinfo": "^1.0.0",
|
||||
"minify-xml": "^2.5.0",
|
||||
"ts-loader": "^9.1.1",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.2.4",
|
||||
"vsce": "^1.87.0",
|
||||
"webpack": "^5.35.1",
|
||||
"webpack-cli": "^4.6.0"
|
||||
"json5": "^2.2.3",
|
||||
"language-texinfo": "^1.1.0",
|
||||
"minify-xml": "^4.4.1",
|
||||
"ts-loader": "^9.5.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.4.3",
|
||||
"webpack": "^5.91.0",
|
||||
"webpack-cli": "^5.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "webpack --mode production",
|
||||
|
@ -72,7 +71,7 @@
|
|||
"max-len": [
|
||||
"warn",
|
||||
{
|
||||
"code": 120
|
||||
"code": 79
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
|
@ -80,7 +79,7 @@
|
|||
}
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.40.0"
|
||||
"vscode": "^1.82.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages",
|
||||
|
@ -88,9 +87,6 @@
|
|||
"Other"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"activationEvents": [
|
||||
"onLanguage:texinfo"
|
||||
],
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
|
@ -167,7 +163,7 @@
|
|||
"texinfo.makeinfo": {
|
||||
"type": "string",
|
||||
"default": "makeinfo",
|
||||
"description": "Path to the makeinfo (or texi2any) command."
|
||||
"description": "Path to the makeinfo (or texi2any) program."
|
||||
},
|
||||
"texinfo.preview.customCSS": {
|
||||
"type": "string",
|
||||
|
@ -205,12 +201,17 @@
|
|||
"texinfo.preview.noValidation": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Supress node cross-reference validation."
|
||||
"description": "Suppress node cross-reference validation."
|
||||
},
|
||||
"texinfo.preview.variables": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"description": "Define variables (as with @set)."
|
||||
},
|
||||
"texinfo.preview.customizationVariables": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"description": "Set customization variables (format: KEY=VAL)"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,38 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2021 CismonX <admin@cismon.net>
|
||||
# Copyright (C) 2021,2024 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
VSIX_FILE_NAME=texinfo-$(json -f package.json version).vsix
|
||||
PACKAGE_JSON_CLEANUP_JS=$(cat ./scripts/package-json-cleanup.js)
|
||||
set -e
|
||||
|
||||
vsce package --baseContentUrl=$(json -f package.json repository.url)/tree
|
||||
version=$(json -f package.json version)
|
||||
vsix_file_name=texinfo-$version.vsix
|
||||
vsce package --baseContentUrl="$(json -f package.json repository.url)/tree"
|
||||
unzip -d "$vsix_file_name.d" "$vsix_file_name"
|
||||
|
||||
cd "$vsix_file_name.d"
|
||||
minify_xml() {
|
||||
minify-xml --no-shorten-namespaces --no-remove-unused-namespaces \
|
||||
--no-remove-unused-default-namespace -i "$1"
|
||||
}
|
||||
minify_xml '[Content_Types].xml'
|
||||
minify_xml extension.vsixmanifest
|
||||
|
||||
unzip -d $VSIX_FILE_NAME{.d,}
|
||||
cd $VSIX_FILE_NAME.d
|
||||
MINIFY_XML_OPTIONS='--no-shorten-namespaces --no-remove-unused-namespaces --no-remove-unused-default-namespace'
|
||||
minify-xml $MINIFY_XML_OPTIONS --output \[Content_Types\].xml{,}
|
||||
minify-xml $MINIFY_XML_OPTIONS --output extension.vsixmanifest{,}
|
||||
cd extension
|
||||
# Minify JSON files.
|
||||
json -j0 -I -e "$PACKAGE_JSON_CLEANUP_JS" -f package.json
|
||||
json -j0 -I -e "$(cat ../../scripts/package-json-cleanup.js)" -f package.json
|
||||
perl -pi -e 'chomp if eof' package.json
|
||||
json5 -o language-configuration.json{,}
|
||||
json5 language-configuration.json > _ && mv _ language-configuration.json
|
||||
# Remove comments from Markdown files.
|
||||
tail -n +9 README.md > _ && mv _ README.md
|
||||
tail -n +9 CHANGELOG.md > _ && mv _ CHANGELOG.md
|
||||
|
||||
cd ext
|
||||
# Minify Perl scripts.
|
||||
if [ -x "$(command -v perltidy)" ]; then
|
||||
# You can install perltidy with `cpan Perl::Tidy`
|
||||
if command -v perltidy; then
|
||||
perltidy --mangle -dac -b html-preview.pm
|
||||
rm html-preview.pm.bak
|
||||
fi
|
||||
cd ../../..
|
||||
|
||||
cd ../../..
|
||||
# Re-package .vsix file.
|
||||
node ./scripts/make-vsix.js $VSIX_FILE_NAME
|
||||
rm -r $VSIX_FILE_NAME.d
|
||||
node ./scripts/make-vsix.js "$vsix_file_name"
|
||||
rm -r "$vsix_file_name.d"
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
#!/usr/bin/env sh
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2020,2021 CismonX <admin@cismon.net>
|
||||
# Copyright (C) 2020,2021,2024 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
SRC_PATH=./node_modules/language-texinfo
|
||||
DEST_PATH=./out/grammars
|
||||
mkdir -p $DEST_PATH
|
||||
# Convert TextMate grammar from CSON to JSON, as VSCode cannot recognize CSON ones.
|
||||
cson2json $SRC_PATH/grammars/texinfo.cson | json5 > $DEST_PATH/texinfo.json
|
||||
set -e
|
||||
|
||||
VERSION=$(json -f package.json version)
|
||||
echo "@set VERSION $VERSION" > ./doc/version.texi
|
||||
src_path=./node_modules/language-texinfo
|
||||
dest_path=./out/grammars
|
||||
|
||||
mkdir -p $dest_path
|
||||
|
||||
# Convert TextMate grammar to JSON, since VSCode cannot recognize CSON ones.
|
||||
cson2json $src_path/grammars/texinfo.cson | json5 > $dest_path/texinfo.json
|
||||
|
||||
version=$(json -f package.json version)
|
||||
echo "@set VERSION $version" > ./doc/version.texi
|
||||
|
|
|
@ -25,10 +25,11 @@ import GlobalContext from './global_context';
|
|||
import { prompt } from './utils/misc';
|
||||
|
||||
/**
|
||||
* Manage mappings between Texinfo documents and corresponding document-specific contexts.
|
||||
* Manage mappings between Texinfo documents and corresponding
|
||||
* document-specific contexts.
|
||||
*/
|
||||
export default class ContextMapping implements vscode.Disposable {
|
||||
|
||||
export default class ContextMapping implements vscode.Disposable
|
||||
{
|
||||
/**
|
||||
* Get context of a Texinfo document. Create one if not exists.
|
||||
*
|
||||
|
@ -36,32 +37,47 @@ export default class ContextMapping implements vscode.Disposable {
|
|||
* @returns
|
||||
*/
|
||||
getDocumentContext(document: vscode.TextDocument) {
|
||||
let documentContext = this.map.get(document);
|
||||
let documentContext = this._map.get(document);
|
||||
if (documentContext === undefined) {
|
||||
documentContext = new DocumentContext(this.globalContext, document);
|
||||
this.map.set(document, documentContext);
|
||||
documentContext
|
||||
= new DocumentContext(this._globalContext, document);
|
||||
this._map.set(document, documentContext);
|
||||
}
|
||||
return documentContext;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.map.forEach(documentContext => documentContext.getPreview()?.close());
|
||||
this._map
|
||||
.forEach(documentContext => documentContext.getPreview()?.close());
|
||||
}
|
||||
|
||||
constructor(private readonly globalContext: GlobalContext) {
|
||||
globalContext.subscribe(
|
||||
vscode.commands.registerTextEditorCommand('texinfo.preview.show', this.showPreview.bind(this)),
|
||||
vscode.commands.registerCommand('texinfo.preview.goto', this.gotoPreview.bind(this)),
|
||||
vscode.workspace.onDidChangeTextDocument(this.onDocumentUpdate.bind(this)),
|
||||
vscode.workspace.onDidCloseTextDocument(this.onDocumentClose.bind(this)),
|
||||
vscode.workspace.onDidSaveTextDocument(this.onDocumentSave.bind(this)),
|
||||
constructor(private readonly _globalContext: GlobalContext) {
|
||||
_globalContext.subscribe(
|
||||
vscode.commands.registerTextEditorCommand(
|
||||
'texinfo.preview.show',
|
||||
this._showPreview.bind(this),
|
||||
),
|
||||
vscode.commands.registerCommand(
|
||||
'texinfo.preview.goto',
|
||||
this._gotoPreview.bind(this),
|
||||
),
|
||||
vscode.workspace.onDidChangeTextDocument(
|
||||
this._onDocumentUpdate.bind(this),
|
||||
),
|
||||
vscode.workspace.onDidCloseTextDocument(
|
||||
this._onDocumentClose.bind(this),
|
||||
),
|
||||
vscode.workspace.onDidSaveTextDocument(
|
||||
this._onDocumentSave.bind(this),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private readonly map = new Map<vscode.TextDocument, DocumentContext>();
|
||||
private readonly _map = new Map<vscode.TextDocument, DocumentContext>();
|
||||
|
||||
private tryGetDocumentContext(document: vscode.TextDocument) {
|
||||
return document.languageId === 'texinfo' ? this.getDocumentContext(document) : undefined;
|
||||
private _tryGetDocumentContext(document: vscode.TextDocument) {
|
||||
return document.languageId === 'texinfo'
|
||||
? this.getDocumentContext(document) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,24 +86,26 @@ export default class ContextMapping implements vscode.Disposable {
|
|||
* @param document
|
||||
* @param nodeName
|
||||
*/
|
||||
private gotoPreview(document: vscode.TextDocument, nodeName: string) {
|
||||
private _gotoPreview(document: vscode.TextDocument, nodeName: string) {
|
||||
this.getDocumentContext(document).initPreview().goto(nodeName);
|
||||
}
|
||||
|
||||
private onDocumentClose(document: vscode.TextDocument) {
|
||||
this.map.get(document)?.getPreview()?.close();
|
||||
this.map.delete(document);
|
||||
private _onDocumentClose(document: vscode.TextDocument) {
|
||||
this._map.get(document)?.getPreview()?.close();
|
||||
this._map.delete(document);
|
||||
}
|
||||
|
||||
private onDocumentSave(document: vscode.TextDocument) {
|
||||
const documentContext = this.tryGetDocumentContext(document);
|
||||
if (documentContext === undefined) return;
|
||||
private _onDocumentSave(document: vscode.TextDocument) {
|
||||
const documentContext = this._tryGetDocumentContext(document);
|
||||
if (documentContext === undefined) {
|
||||
return;
|
||||
}
|
||||
documentContext.foldingRange.clear();
|
||||
documentContext.getPreview()?.updateWebview();
|
||||
}
|
||||
|
||||
private onDocumentUpdate(event: vscode.TextDocumentChangeEvent) {
|
||||
const documentContext = this.tryGetDocumentContext(event.document);
|
||||
private _onDocumentUpdate(event: vscode.TextDocumentChangeEvent) {
|
||||
const documentContext = this._tryGetDocumentContext(event.document);
|
||||
if (documentContext?.foldingRange.update(event.contentChanges)) {
|
||||
documentContext.documentSymbol.clear();
|
||||
}
|
||||
|
@ -98,11 +116,14 @@ export default class ContextMapping implements vscode.Disposable {
|
|||
*
|
||||
* @param editor The editor where the document is being held.
|
||||
*/
|
||||
private async showPreview(editor: vscode.TextEditor) {
|
||||
private async _showPreview(editor: vscode.TextEditor) {
|
||||
const document = editor.document;
|
||||
// Only show preview for saved files, as we're not gonna send document content to `makeinfo` via STDIN.
|
||||
// Only show preview for saved files, as we're not gonna send
|
||||
// document content to `makeinfo` via STDIN.
|
||||
// Instead, the file will be loaded from disk.
|
||||
if (document.isUntitled && !await prompt('Save this document to display preview.', 'Save')) {
|
||||
if (document.isUntitled &&
|
||||
!await prompt('Save this document to display preview.', 'Save')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (document.isDirty && !await document.save()) {
|
||||
|
|
|
@ -28,25 +28,28 @@ import PreviewContext from './preview';
|
|||
/**
|
||||
* Holds all contexts for a Texinfo document.
|
||||
*/
|
||||
export default class DocumentContext {
|
||||
|
||||
export default class DocumentContext
|
||||
{
|
||||
readonly foldingRange = new FoldingRangeContext(this);
|
||||
|
||||
readonly documentSymbol = new DocumentSymbolContext(this);
|
||||
|
||||
initPreview() {
|
||||
return this.preview ??= new PreviewContext(this);
|
||||
return this._preview ??= new PreviewContext(this);
|
||||
}
|
||||
|
||||
getPreview() {
|
||||
return this.preview;
|
||||
return this._preview;
|
||||
}
|
||||
|
||||
closePreview() {
|
||||
this.preview = undefined;
|
||||
this._preview = undefined;
|
||||
}
|
||||
|
||||
constructor(readonly globalContext: GlobalContext, readonly document: vscode.TextDocument) {}
|
||||
constructor(
|
||||
readonly globalContext: GlobalContext,
|
||||
readonly document: vscode.TextDocument,
|
||||
) {}
|
||||
|
||||
private preview?: PreviewContext;
|
||||
private _preview?: PreviewContext;
|
||||
}
|
||||
|
|
|
@ -27,43 +27,52 @@ import { FoldingRange, Optional } from '../utils/types';
|
|||
/**
|
||||
* Context for symbols in a Texinfo document.
|
||||
*/
|
||||
export default class DocumentSymbolContext {
|
||||
|
||||
export default class DocumentSymbolContext
|
||||
{
|
||||
get documentSymbols() {
|
||||
return this._documentSymbols ??= this.calculcateDocumentSymbols();
|
||||
return this._documentSymbols ??= this._calculateDocumentSymbols();
|
||||
}
|
||||
|
||||
clear() {
|
||||
this._documentSymbols = undefined;
|
||||
}
|
||||
|
||||
constructor(private readonly documentContext: DocumentContext) {}
|
||||
constructor(private readonly _documentContext: DocumentContext) {}
|
||||
|
||||
private _documentSymbols?: vscode.DocumentSymbol[];
|
||||
|
||||
private readonly document = this.documentContext.document;
|
||||
private readonly _document = this._documentContext.document;
|
||||
|
||||
/**
|
||||
* Calculate document symbols based on folding ranges.
|
||||
*/
|
||||
private calculcateDocumentSymbols() {
|
||||
const ranges = Array<Optional<FoldingRange>>(this.document.lineCount);
|
||||
this.documentContext.foldingRange.foldingRanges
|
||||
private _calculateDocumentSymbols() {
|
||||
const ranges = Array<Optional<FoldingRange>>(this._document.lineCount);
|
||||
this._documentContext.foldingRange.foldingRanges
|
||||
.filter(range => range.kind === undefined)
|
||||
.forEach(range => ranges[range.start] = range);
|
||||
return foldingRangeToSymbols(ranges, 0, ranges.length);
|
||||
}
|
||||
}
|
||||
|
||||
function foldingRangeToSymbols(ranges: readonly Optional<FoldingRange>[], start: number, end: number) {
|
||||
function foldingRangeToSymbols(
|
||||
ranges: readonly Optional<FoldingRange>[],
|
||||
start: number,
|
||||
end: number,
|
||||
) {
|
||||
const symbols = <vscode.DocumentSymbol[]>[];
|
||||
for (let idx = start; idx < end; ++idx) {
|
||||
const node = ranges[idx];
|
||||
if (node === undefined) continue;
|
||||
const range = lineNumToRange(idx, node.end);
|
||||
const selectionRange = lineNumToRange(idx);
|
||||
const symbol = new vscode.DocumentSymbol('@' + node.name, node.detail, vscode.SymbolKind.String,
|
||||
range, selectionRange);
|
||||
if (node === undefined) {
|
||||
continue;
|
||||
}
|
||||
const symbol = new vscode.DocumentSymbol(
|
||||
'@' + node.name,
|
||||
node.detail,
|
||||
vscode.SymbolKind.String,
|
||||
lineNumToRange(idx, node.end), // full range
|
||||
lineNumToRange(idx), // selection range
|
||||
);
|
||||
symbol.children = foldingRangeToSymbols(ranges, idx + 1, node.end);
|
||||
symbols.push(symbol);
|
||||
idx = node.end;
|
||||
|
|
|
@ -27,24 +27,24 @@ import DocumentContext from './document';
|
|||
/**
|
||||
* Stores information about folding ranges for a document.
|
||||
*
|
||||
* Actually, more than folding ranges (e.g. code lens) is handled within this context, so I believe
|
||||
* we should use another name...
|
||||
* Actually, more than folding ranges (e.g. code lens) is handled within
|
||||
* this context, so perhaps we should use another name...
|
||||
*/
|
||||
export default class FoldingRangeContext {
|
||||
|
||||
export default class FoldingRangeContext
|
||||
{
|
||||
/**
|
||||
* Get VSCode folding ranges from the context.
|
||||
*/
|
||||
get foldingRanges() {
|
||||
return this._foldingRanges ?? this.calculateFoldingRanges();
|
||||
return this._foldingRanges ?? this._calculateFoldingRanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get node values of document as VSCode code lenses.
|
||||
*/
|
||||
get nodeValues() {
|
||||
this._foldingRanges ?? this.calculateFoldingRanges();
|
||||
return this.nodes;
|
||||
this._foldingRanges ?? this._calculateFoldingRanges();
|
||||
return this._nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,14 +53,18 @@ export default class FoldingRangeContext {
|
|||
* @param events Events describing the changes in the document.
|
||||
*/
|
||||
update(events: readonly vscode.TextDocumentContentChangeEvent[]) {
|
||||
this.contentMayChange = true;
|
||||
if (this._foldingRanges === undefined) return false;
|
||||
const eol = this.document.eol === vscode.EndOfLine.LF ? '\n' : '\r\n';
|
||||
this._contentMayChange = true;
|
||||
if (this._foldingRanges === undefined) {
|
||||
return false;
|
||||
}
|
||||
const eol = this._document.eol === vscode.EndOfLine.LF ? '\n' : '\r\n';
|
||||
for (const event of events) {
|
||||
// Clear cached folding range when line count changes.
|
||||
if (event.text.split(eol).length !== 1 || event.range.start.line !== event.range.end.line) {
|
||||
if (event.text.split(eol).length !== 1 ||
|
||||
event.range.start.line !== event.range.end.line
|
||||
) {
|
||||
this._foldingRanges = undefined;
|
||||
this.nodes = [];
|
||||
this._nodes = [];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -68,40 +72,48 @@ export default class FoldingRangeContext {
|
|||
}
|
||||
|
||||
clear() {
|
||||
if (this.contentMayChange) {
|
||||
if (this._contentMayChange) {
|
||||
this._foldingRanges = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
constructor(private readonly documentContext: DocumentContext) {}
|
||||
constructor(private readonly _documentContext: DocumentContext) {}
|
||||
|
||||
private readonly document = this.documentContext.document;
|
||||
private readonly _document = this._documentContext.document;
|
||||
|
||||
/**
|
||||
* Regex for matching subsection/section/chapter (-like) commands.
|
||||
*/
|
||||
private static readonly nodeFormat = RegExp('^@(?:(node)|(subsection|unnumberedsubsec|appendixsubsec|subheading)|' +
|
||||
'(section|unnumberedsec|appendixsec|heading)|(chapter|unnumbered|appendix|majorheading|chapheading)) (.*)$');
|
||||
private static readonly _nodeFormat = RegExp('^@(?:(node)|' +
|
||||
'(subsection|unnumberedsubsec|appendixsubsec|subheading)|' +
|
||||
'(section|unnumberedsec|appendixsec|heading)|' +
|
||||
'(chapter|unnumbered|appendix|majorheading|chapheading)) (.*)$');
|
||||
|
||||
private _foldingRanges?: FoldingRange[];
|
||||
|
||||
private nodes = <vscode.CodeLens[]>[];
|
||||
private _nodes = <vscode.CodeLens[]>[];
|
||||
|
||||
private commentRange?: Range;
|
||||
private headerStart?: number;
|
||||
private closingChapter?: number;
|
||||
private closingSection?: number;
|
||||
private closingSubsection?: number;
|
||||
private _commentRange?: Range;
|
||||
private _headerStart?: number;
|
||||
private _closingChapter?: number;
|
||||
private _closingSection?: number;
|
||||
private _closingSubsection?: number;
|
||||
|
||||
private contentMayChange = true;
|
||||
private _contentMayChange = true;
|
||||
|
||||
private addRange(start: number, end: number, extraArgs: {
|
||||
private _addRange(start: number, end: number, extraArgs: {
|
||||
name?: string,
|
||||
detail?: string,
|
||||
kind?: vscode.FoldingRangeKind
|
||||
}) {
|
||||
(this._foldingRanges ??= [])
|
||||
.push({ name: extraArgs.name ?? '', detail: extraArgs.detail ?? '', start, end, kind: extraArgs.kind });
|
||||
const items = {
|
||||
name: extraArgs.name ?? '',
|
||||
detail: extraArgs.detail ?? '',
|
||||
start,
|
||||
end,
|
||||
kind: extraArgs.kind,
|
||||
};
|
||||
(this._foldingRanges ??= []).push(items);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,30 +122,36 @@ export default class FoldingRangeContext {
|
|||
* @param start Starting line number.
|
||||
* @param end Ending line number.
|
||||
*/
|
||||
private calculateFoldingRanges() {
|
||||
this.contentMayChange = false;
|
||||
private _calculateFoldingRanges() {
|
||||
this._contentMayChange = false;
|
||||
this._foldingRanges = [];
|
||||
this.clearTemporaries();
|
||||
this._clearTemporaries();
|
||||
let closingBlocks = <NamedLine[]>[];
|
||||
let lastLine = this.document.lineCount - 1;
|
||||
let lastLine = this._document.lineCount - 1;
|
||||
let verbatim = false;
|
||||
for (let idx = lastLine; idx >= 0; --idx) {
|
||||
const line = this.document.lineAt(idx).text.trimLeft();
|
||||
if (!line.startsWith('@')) continue;
|
||||
const line = this._document.lineAt(idx).text.trimLeft();
|
||||
if (!line.startsWith('@')) {
|
||||
continue;
|
||||
}
|
||||
if (!verbatim) {
|
||||
if (line === '@bye') {
|
||||
lastLine = idx;
|
||||
// Abort anything after `@bye`.
|
||||
this._foldingRanges = [];
|
||||
closingBlocks = [];
|
||||
this.clearTemporaries();
|
||||
this._clearTemporaries();
|
||||
continue;
|
||||
}
|
||||
if (this._processComment(line, idx)) {
|
||||
continue;
|
||||
}
|
||||
if (this.processComment(line, idx)) continue;
|
||||
}
|
||||
// Process block.
|
||||
if (line.startsWith('@end ')) {
|
||||
if (verbatim) continue;
|
||||
if (verbatim) {
|
||||
continue;
|
||||
}
|
||||
const name = line.substring(5).trimRight();
|
||||
if (name === 'verbatim') {
|
||||
verbatim = true;
|
||||
|
@ -141,93 +159,123 @@ export default class FoldingRangeContext {
|
|||
closingBlocks.push({ name: name, line: idx });
|
||||
continue;
|
||||
}
|
||||
if (!verbatim && this.processNode(line, idx, lastLine)) continue;
|
||||
if (!verbatim && this._processNode(line, idx, lastLine)) {
|
||||
continue;
|
||||
}
|
||||
const closingBlock = closingBlocks.pop();
|
||||
if (closingBlock === undefined) continue;
|
||||
if (line.substring(1, closingBlock.name.length + 2).trim() === closingBlock.name) {
|
||||
this.addRange(idx, closingBlock.line, { name: closingBlock.name });
|
||||
// If `verbatim == true` goes here, this line must be the `@verbatim` line.
|
||||
if (closingBlock === undefined) {
|
||||
continue;
|
||||
}
|
||||
const name = closingBlock.name;
|
||||
if (line.substring(1, name.length + 2).trim() === name) {
|
||||
this._addRange(idx, closingBlock.line, { name: name });
|
||||
// If `verbatim == true` goes here,
|
||||
// this line must be the `@verbatim` line.
|
||||
verbatim = false;
|
||||
} else {
|
||||
closingBlocks.push(closingBlock);
|
||||
}
|
||||
}
|
||||
if (this.commentRange !== undefined) {
|
||||
this.addRange(this.commentRange.start, this.commentRange.end, { kind: vscode.FoldingRangeKind.Comment });
|
||||
if (this._commentRange !== undefined) {
|
||||
this._addRange(
|
||||
this._commentRange.start,
|
||||
this._commentRange.end,
|
||||
{ kind: vscode.FoldingRangeKind.Comment },
|
||||
);
|
||||
}
|
||||
return this._foldingRanges;
|
||||
}
|
||||
|
||||
private clearTemporaries() {
|
||||
this.commentRange = undefined;
|
||||
this.headerStart = undefined;
|
||||
this.nodes = [];
|
||||
this.closingSubsection = this.closingSection = this.closingChapter = undefined;
|
||||
private _clearTemporaries() {
|
||||
this._commentRange = undefined;
|
||||
this._headerStart = undefined;
|
||||
this._nodes = [];
|
||||
this._closingSubsection = this._closingSection = this._closingChapter
|
||||
= undefined;
|
||||
}
|
||||
|
||||
private getLastTextLine(lineNum: number, limit = 3) {
|
||||
private _getLastTextLine(lineNum: number, limit = 3) {
|
||||
for (let idx = lineNum; idx > lineNum - limit; --idx) {
|
||||
const line = this.document.lineAt(idx).text;
|
||||
if (line.startsWith('@node ')) return idx - 1;
|
||||
if (line === '') return idx;
|
||||
const line = this._document.lineAt(idx).text;
|
||||
if (line.startsWith('@node ')) {
|
||||
return idx - 1;
|
||||
}
|
||||
if (line === '') {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return lineNum;
|
||||
}
|
||||
|
||||
private processComment(lineText: string, lineNum: number) {
|
||||
if (!lineText.startsWith('@c')) return false;
|
||||
if (!lineText.startsWith(' ', 2) && !lineText.startsWith('omment ', 2)) {
|
||||
private _processComment(lineText: string, lineNum: number) {
|
||||
if (!lineText.startsWith('@c')) {
|
||||
return false;
|
||||
}
|
||||
if (lineText.charAt(2) != ' ' && !lineText.startsWith('omment ', 2)) {
|
||||
return false;
|
||||
}
|
||||
// Check for opening/closing header.
|
||||
if (lineText.startsWith('%**', lineText[2] === ' ' ? 3 : 9)) {
|
||||
if (this.headerStart === undefined) {
|
||||
this.headerStart = lineNum;
|
||||
if (this._headerStart === undefined) {
|
||||
this._headerStart = lineNum;
|
||||
} else {
|
||||
this.addRange(lineNum, this.headerStart, { kind: vscode.FoldingRangeKind.Region });
|
||||
this.headerStart = undefined;
|
||||
this._addRange(lineNum, this._headerStart,
|
||||
{ kind: vscode.FoldingRangeKind.Region });
|
||||
this._headerStart = undefined;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (this.commentRange === undefined) {
|
||||
this.commentRange = { start: lineNum, end: lineNum };
|
||||
} else if (this.commentRange.start - 1 === lineNum) {
|
||||
this.commentRange.start = lineNum;
|
||||
if (this._commentRange === undefined) {
|
||||
this._commentRange = { start: lineNum, end: lineNum };
|
||||
} else if (this._commentRange.start - 1 === lineNum) {
|
||||
this._commentRange.start = lineNum;
|
||||
} else {
|
||||
this.addRange(this.commentRange.start, this.commentRange.end, { kind: vscode.FoldingRangeKind.Comment });
|
||||
this.commentRange = undefined;
|
||||
this._addRange(this._commentRange.start, this._commentRange.end,
|
||||
{ kind: vscode.FoldingRangeKind.Comment });
|
||||
this._commentRange = undefined;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private processNode(lineText: string, lineNum: number, lastLineNum: number) {
|
||||
const result = lineText.match(FoldingRangeContext.nodeFormat);
|
||||
if (result === null) return false;
|
||||
private _processNode(
|
||||
lineText: string,
|
||||
lineNum: number,
|
||||
lastLineNum: number,
|
||||
) {
|
||||
const result = lineText.match(FoldingRangeContext._nodeFormat);
|
||||
if (result === null) {
|
||||
return false;
|
||||
}
|
||||
// Node identifier.
|
||||
if (result[1] !== undefined) {
|
||||
this.nodes.push(new vscode.CodeLens(lineNumToRange(lineNum), {
|
||||
this._nodes.push(new vscode.CodeLens(lineNumToRange(lineNum), {
|
||||
title: '$(go-to-file) Goto node in preview',
|
||||
command: 'texinfo.preview.goto',
|
||||
arguments: [this.document, result[5]],
|
||||
arguments: [this._document, result[5]],
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
// Subsection level node.
|
||||
if (result[2] !== undefined) {
|
||||
this.addRange(lineNum, this.closingSubsection ?? lastLineNum, { name: result[2], detail: result[5] });
|
||||
this.closingSubsection = this.getLastTextLine(lineNum - 1);
|
||||
this._addRange(lineNum, this._closingSubsection ?? lastLineNum,
|
||||
{ name: result[2], detail: result[5] });
|
||||
this._closingSubsection = this._getLastTextLine(lineNum - 1);
|
||||
return true;
|
||||
}
|
||||
// Section level node.
|
||||
if (result[3] !== undefined) {
|
||||
this.addRange(lineNum, this.closingSection ?? lastLineNum, { name: result[3], detail: result[5] });
|
||||
this.closingSubsection = this.closingSection = this.getLastTextLine(lineNum - 1);
|
||||
this._addRange(lineNum, this._closingSection ?? lastLineNum,
|
||||
{ name: result[3], detail: result[5] });
|
||||
this._closingSubsection = this._closingSection
|
||||
= this._getLastTextLine(lineNum - 1);
|
||||
return true;
|
||||
}
|
||||
// Chapter level node.
|
||||
if (result[4] !== undefined) {
|
||||
this.addRange(lineNum, this.closingChapter ?? lastLineNum, { name: result[4], detail: result[5] });
|
||||
this.closingSubsection = this.closingSection = this.closingChapter = this.getLastTextLine(lineNum - 1);
|
||||
this._addRange(lineNum, this._closingChapter ?? lastLineNum,
|
||||
{ name: result[4], detail: result[5] });
|
||||
this._closingSubsection = this._closingSection
|
||||
= this._closingChapter = this._getLastTextLine(lineNum - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -28,85 +28,108 @@ import { getNodeHtmlRef, prompt } from '../utils/misc';
|
|||
/**
|
||||
* Stores information of a Texinfo document preview.
|
||||
*/
|
||||
export default class PreviewContext {
|
||||
|
||||
export default class PreviewContext
|
||||
{
|
||||
close() {
|
||||
this.disposables.forEach(event => event.dispose());
|
||||
this.panel.dispose();
|
||||
this.documentContext.closePreview();
|
||||
this._disposables.forEach(event => event.dispose());
|
||||
this._panel.dispose();
|
||||
this._documentContext.closePreview();
|
||||
// Only show diagnostic information when the preview is active.
|
||||
this.diagnosis.delete(this.document);
|
||||
this._diagnosis.delete(this._document);
|
||||
}
|
||||
|
||||
goto(nodeName: string) {
|
||||
this.panel.webview.postMessage({ command: 'goto', value: getNodeHtmlRef(nodeName) });
|
||||
const message = { command: 'goto', value: getNodeHtmlRef(nodeName) };
|
||||
this._webview.postMessage(message);
|
||||
}
|
||||
|
||||
show() {
|
||||
this.panel.reveal();
|
||||
this._panel.reveal();
|
||||
}
|
||||
|
||||
async updateWebview() {
|
||||
if (this.updating) {
|
||||
this.pendingUpdate = true;
|
||||
if (this._updating) {
|
||||
this._pendingUpdate = true;
|
||||
return;
|
||||
}
|
||||
this.updating = true;
|
||||
this.pendingUpdate = false;
|
||||
// Inform the user that the preview is updating if `makeinfo` takes too long.
|
||||
setTimeout(() => this.updating && this.updateTitle(), 500);
|
||||
const initFile = this.globalContext.extensionPath + '/ext/html-preview.pm';
|
||||
const converter = new Converter(this.document.fileName, initFile, this.globalContext.options, this.logger);
|
||||
const { data, error } = await converter.toHTML(path => this.panel.webview.asWebviewUri(path), this.script);
|
||||
this._updating = true;
|
||||
this._pendingUpdate = false;
|
||||
// Inform the user that the preview is updating, when `makeinfo`
|
||||
// takes too long.
|
||||
setTimeout(() => this._updating && this._updateTitle(), 500);
|
||||
const converter = new Converter(
|
||||
this._document.fileName,
|
||||
this._globalContext.path + '/ext/html-preview.pm',
|
||||
this._globalContext.options,
|
||||
this._logger,
|
||||
);
|
||||
const { data, error } = await converter.toHTML(
|
||||
path => this._webview.asWebviewUri(path),
|
||||
this._script,
|
||||
);
|
||||
if (error) {
|
||||
this.logger.log(error);
|
||||
this.diagnosis.update(this.document, error);
|
||||
this._logger.log(error);
|
||||
this._diagnosis.update(this._document, error);
|
||||
} else {
|
||||
this.diagnosis.delete(this.document);
|
||||
this._diagnosis.delete(this._document);
|
||||
}
|
||||
if (data === undefined) {
|
||||
prompt(`Failed to show preview for ${this.document.fileName}.`, 'Show log', true)
|
||||
.then(result => result && this.logger.show());
|
||||
prompt(`Failed to show preview for ${this._document.fileName}.`,
|
||||
'Show log', true)
|
||||
.then(result => result && this._logger.show());
|
||||
} else {
|
||||
this.panel.webview.html = data;
|
||||
this._webview.html = data;
|
||||
}
|
||||
this.updating = false;
|
||||
this.updateTitle();
|
||||
this.pendingUpdate && this.updateWebview();
|
||||
this._updating = false;
|
||||
this._updateTitle();
|
||||
this._pendingUpdate && this.updateWebview();
|
||||
}
|
||||
|
||||
constructor(private readonly documentContext: DocumentContext) {
|
||||
this.panel = vscode.window.createWebviewPanel('texinfo.preview', '', vscode.ViewColumn.Beside,
|
||||
{ enableFindWidget: true, retainContextWhenHidden: true, enableScripts: true });
|
||||
this.disposables.push(this.panel.onDidDispose(() => this.close()));
|
||||
this.updateTitle();
|
||||
constructor(private readonly _documentContext: DocumentContext) {
|
||||
const options = {
|
||||
enableFindWidget: true,
|
||||
retainContextWhenHidden: true,
|
||||
enableScripts: true,
|
||||
};
|
||||
this._panel = vscode.window.createWebviewPanel(
|
||||
'texinfo.preview', '',
|
||||
vscode.ViewColumn.Beside,
|
||||
options,
|
||||
);
|
||||
this._webview = this._panel.webview;
|
||||
this._disposables.push(this._panel.onDidDispose(() => this.close()));
|
||||
this._updateTitle();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
private readonly document = this.documentContext.document;
|
||||
private readonly globalContext = this.documentContext.globalContext;
|
||||
private readonly diagnosis = this.globalContext.diagnosis;
|
||||
private readonly logger = this.globalContext.logger;
|
||||
private readonly _document = this._documentContext.document;
|
||||
private readonly _globalContext = this._documentContext.globalContext;
|
||||
private readonly _diagnosis = this._globalContext.diagnosis;
|
||||
private readonly _logger = this._globalContext.logger;
|
||||
|
||||
private readonly disposables = <vscode.Disposable[]>[];
|
||||
private readonly _disposables = <vscode.Disposable[]>[];
|
||||
|
||||
private readonly panel: vscode.WebviewPanel;
|
||||
private readonly _panel: vscode.WebviewPanel;
|
||||
private readonly _webview: vscode.Webview;
|
||||
|
||||
/**
|
||||
* Whether a preview update request is pending.
|
||||
*/
|
||||
private pendingUpdate = false;
|
||||
private _pendingUpdate = false;
|
||||
|
||||
/**
|
||||
* Whether the preview is updating.
|
||||
*/
|
||||
private updating = false;
|
||||
private _updating = false;
|
||||
|
||||
/**
|
||||
* Generate script used for jumping to the corresponding location of preview with code lens.
|
||||
* Generate script used for jumping to the corresponding location of
|
||||
* preview with code lens.
|
||||
*/
|
||||
private get script() {
|
||||
if (!this.globalContext.options.enableCodeLens) return undefined;
|
||||
private get _script() {
|
||||
if (!this._globalContext.options.enableCodeLens) {
|
||||
return undefined;
|
||||
}
|
||||
return "window.addEventListener('message', event => {" +
|
||||
"const message = event.data;" +
|
||||
"switch (message.command) {" +
|
||||
|
@ -119,9 +142,9 @@ export default class PreviewContext {
|
|||
"})";
|
||||
}
|
||||
|
||||
private updateTitle() {
|
||||
const updating = this.updating ? '(Updating) ' : '';
|
||||
const fileName = path.basename(this.document.fileName);
|
||||
this.panel.title = `${updating}Preview ${fileName}`;
|
||||
private _updateTitle() {
|
||||
const updating = this._updating ? '(Updating) ' : '';
|
||||
const fileName = path.basename(this._document.fileName);
|
||||
this._panel.title = `${updating}Preview ${fileName}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,22 +19,23 @@
|
|||
* vscode-texinfo. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import { lineNumToRange } from './utils/misc';
|
||||
import { escapeStringForRegExp, lineNumToRange } from './utils/misc';
|
||||
import { isDefined } from './utils/types';
|
||||
|
||||
/**
|
||||
* Manage diagnostic information of Texinfo documents.
|
||||
*/
|
||||
export default class Diagnosis implements vscode.Disposable {
|
||||
|
||||
export default class Diagnosis implements vscode.Disposable
|
||||
{
|
||||
/**
|
||||
* Remove a document's diagnostic entry from the collection.
|
||||
*
|
||||
* @param document
|
||||
*/
|
||||
delete(document: vscode.TextDocument) {
|
||||
this.diagnostics.delete(document.uri);
|
||||
this._diagnostics.delete(document.uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,19 +45,29 @@ export default class Diagnosis implements vscode.Disposable {
|
|||
* @param logText
|
||||
*/
|
||||
update(document: vscode.TextDocument, logText: string) {
|
||||
const fileName = document.uri.path;
|
||||
const fileName = path.basename(document.uri.path);
|
||||
const regex = new RegExp(`${escapeStringForRegExp(fileName)}:\\d+:`);
|
||||
const diagnostics = logText.split('\n')
|
||||
.filter(line => line.startsWith(fileName))
|
||||
.map(line => logLineToDiagnostic(line.substring(fileName.length + 1)))
|
||||
.map(line => line.length > 0 ? line.match(regex) : null)
|
||||
.map(result => {
|
||||
const index = result?.index;
|
||||
const line = result?.input;
|
||||
if (index === undefined || line === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const logText = line.substring(index + fileName.length + 1);
|
||||
return logToDiagnostic(logText);
|
||||
})
|
||||
.filter(isDefined);
|
||||
this.diagnostics.set(document.uri, diagnostics);
|
||||
this._diagnostics.set(document.uri, diagnostics);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.diagnostics.dispose();
|
||||
this._diagnostics.dispose();
|
||||
}
|
||||
|
||||
private readonly diagnostics = vscode.languages.createDiagnosticCollection('texinfo');
|
||||
private readonly _diagnostics
|
||||
= vscode.languages.createDiagnosticCollection('texinfo');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,11 +76,15 @@ export default class Diagnosis implements vscode.Disposable {
|
|||
* @param lineText
|
||||
* @returns
|
||||
*/
|
||||
function logLineToDiagnostic(lineText: string) {
|
||||
function logToDiagnostic(lineText: string) {
|
||||
const lineNum = parseInt(lineText) - 1;
|
||||
// Ignore error that does not correspond a line in document.
|
||||
if (isNaN(lineNum)) return undefined;
|
||||
// Ignore error that does not correspond to a line in document.
|
||||
if (isNaN(lineNum)) {
|
||||
return undefined;
|
||||
}
|
||||
const message = lineText.substring(lineNum.toString().length + 2);
|
||||
const severity = message.startsWith('warning:') ? vscode.DiagnosticSeverity.Warning : undefined;
|
||||
const severity = message.startsWith('warning:')
|
||||
? vscode.DiagnosticSeverity.Warning
|
||||
: undefined;
|
||||
return new vscode.Diagnostic(lineNumToRange(lineNum), message, severity);
|
||||
}
|
||||
|
|
|
@ -33,33 +33,54 @@ import FoldingRangeProvider from './providers/folding_range';
|
|||
/**
|
||||
* Manage extension-level global-scope contexts.
|
||||
*/
|
||||
export default class GlobalContext {
|
||||
|
||||
export default class GlobalContext
|
||||
{
|
||||
readonly contextMapping = new ContextMapping(this);
|
||||
readonly diagnosis = new Diagnosis;
|
||||
readonly indicator = new Indicator(this);
|
||||
readonly logger = new Logger;
|
||||
|
||||
readonly extensionPath = this.context.extensionPath;
|
||||
readonly path = this._context.extensionPath;
|
||||
|
||||
/**
|
||||
* Note: `Options`' no singleton. Do not wire directly, always use `globalContext.options` instead.
|
||||
* Note: `Options`' no singleton.
|
||||
*
|
||||
* Do not wire directly, always use `globalContext.options` instead.
|
||||
*/
|
||||
get options() {
|
||||
return this._options ??= new Options;
|
||||
}
|
||||
|
||||
subscribe(...items: vscode.Disposable[]) {
|
||||
this.context.subscriptions.push(...items);
|
||||
this._context.subscriptions.push(...items);
|
||||
}
|
||||
|
||||
constructor(private readonly context: vscode.ExtensionContext) {
|
||||
this.subscribe(this.contextMapping, this.diagnosis, this.indicator, this.logger,
|
||||
vscode.languages.registerCodeLensProvider('texinfo', new CodeLensProvider(this)),
|
||||
vscode.languages.registerCompletionItemProvider('texinfo', new CompletionItemProvider(this), '@'),
|
||||
vscode.languages.registerDocumentSymbolProvider('texinfo', new DocumentSymbolProvider(this)),
|
||||
vscode.languages.registerFoldingRangeProvider('texinfo', new FoldingRangeProvider(this)),
|
||||
vscode.workspace.onDidChangeConfiguration(() => this._options = undefined),
|
||||
constructor(private readonly _context: vscode.ExtensionContext) {
|
||||
this.subscribe(
|
||||
this.contextMapping,
|
||||
this.diagnosis,
|
||||
this.indicator,
|
||||
this.logger,
|
||||
vscode.languages.registerCodeLensProvider(
|
||||
'texinfo',
|
||||
new CodeLensProvider(this),
|
||||
),
|
||||
vscode.languages.registerCompletionItemProvider(
|
||||
'texinfo',
|
||||
new CompletionItemProvider(this),
|
||||
'@',
|
||||
),
|
||||
vscode.languages.registerDocumentSymbolProvider(
|
||||
'texinfo',
|
||||
new DocumentSymbolProvider(this),
|
||||
),
|
||||
vscode.languages.registerFoldingRangeProvider(
|
||||
'texinfo',
|
||||
new FoldingRangeProvider(this),
|
||||
),
|
||||
vscode.workspace.onDidChangeConfiguration(
|
||||
() => this._options = undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* indicator.ts
|
||||
*
|
||||
* Copyright (C) 2020,2021 CismonX <admin@cismon.net>
|
||||
* Copyright (C) 2020,2021,2024 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of vscode-texinfo.
|
||||
*
|
||||
|
@ -26,34 +26,41 @@ import { exec } from './utils/misc';
|
|||
/**
|
||||
* Shows whether GNU Texinfo is properly installed and configured.
|
||||
*/
|
||||
export default class Indicator implements vscode.Disposable {
|
||||
|
||||
export default class Indicator implements vscode.Disposable
|
||||
{
|
||||
get canDisplayPreview() {
|
||||
return this._canDisplayPreview;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.statusBarItem.dispose();
|
||||
this._statusBarItem.dispose();
|
||||
}
|
||||
|
||||
constructor(private readonly globalContext: GlobalContext) {
|
||||
globalContext.subscribe(
|
||||
vscode.commands.registerCommand('texinfo.indicator.click', this.click.bind(this)),
|
||||
vscode.window.onDidChangeActiveTextEditor(this.refresh.bind(this)),
|
||||
constructor(private readonly _globalContext: GlobalContext) {
|
||||
_globalContext.subscribe(
|
||||
vscode.commands.registerCommand(
|
||||
'texinfo.indicator.click',
|
||||
this._click.bind(this),
|
||||
),
|
||||
vscode.window.onDidChangeActiveTextEditor(
|
||||
this._refresh.bind(this),
|
||||
),
|
||||
);
|
||||
this.updateStatus().then(() => this.refresh(vscode.window.activeTextEditor));
|
||||
this._updateStatus()
|
||||
.then(() => this._refresh(vscode.window.activeTextEditor));
|
||||
}
|
||||
|
||||
private _canDisplayPreview = false;
|
||||
|
||||
private readonly statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
|
||||
private readonly _statusBarItem = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Right, 100);
|
||||
|
||||
/**
|
||||
* Calls when the status bar item is clicked.
|
||||
*/
|
||||
private async click() {
|
||||
await this.updateStatus();
|
||||
this.refresh(vscode.window.activeTextEditor);
|
||||
private async _click() {
|
||||
await this._updateStatus();
|
||||
this._refresh(vscode.window.activeTextEditor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,39 +68,46 @@ export default class Indicator implements vscode.Disposable {
|
|||
*
|
||||
* @param editor
|
||||
*/
|
||||
private refresh(editor?: vscode.TextEditor) {
|
||||
private _refresh(editor?: vscode.TextEditor) {
|
||||
if (editor?.document.languageId === 'texinfo') {
|
||||
this.statusBarItem.show();
|
||||
this._statusBarItem.show();
|
||||
} else {
|
||||
this.statusBarItem.hide();
|
||||
this._statusBarItem.hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the installation status of GNU Texinfo, by checking `makeinfo --version`.
|
||||
* Update the installation status of GNU Texinfo,
|
||||
* by checking `makeinfo --version`.
|
||||
*/
|
||||
private async updateStatus() {
|
||||
const options = this.globalContext.options;
|
||||
const output = await exec(options.makeinfo, ['--version'], options.maxSize);
|
||||
private async _updateStatus() {
|
||||
const options = this._globalContext.options;
|
||||
const output
|
||||
= await exec(options.makeinfo, ['--version'], options.maxSize);
|
||||
const result = output.data?.match(/\(GNU texinfo\) (.*)\n/);
|
||||
let tooltip = '', icon: string, version = '';
|
||||
if (result && result[1]) {
|
||||
version = result[1];
|
||||
if (!isNaN(+version) && +version < 6.7) {
|
||||
icon = '$(warning)';
|
||||
tooltip = `GNU Texinfo (${options.makeinfo}) is outdated (${version} < 6.7).`;
|
||||
} else {
|
||||
// Unrecognizable version. Assume it is okay.
|
||||
icon = '$(check)';
|
||||
const version = result?.[1] ?? '';
|
||||
let tooltip = '', icon: string;
|
||||
if (version) {
|
||||
icon = '$(check)';
|
||||
const verArr = version.split('.');
|
||||
if (version.length >= 2) {
|
||||
const verMajor = parseInt(verArr[0], 10);
|
||||
const verMinor = parseInt(verArr[1], 10);
|
||||
if (verMajor < 7 || verMinor < 1) {
|
||||
icon = '$(warning)';
|
||||
tooltip = `GNU Texinfo (${options.makeinfo}) ` +
|
||||
`is outdated (${version} < 7.1).`;
|
||||
}
|
||||
}
|
||||
this._canDisplayPreview = true;
|
||||
} else {
|
||||
icon = '$(close)';
|
||||
tooltip = `GNU Texinfo (${options.makeinfo}) is not correctly installed or configured.`;
|
||||
tooltip = `GNU Texinfo (${options.makeinfo}) ` +
|
||||
`is not correctly installed or configured.`;
|
||||
this._canDisplayPreview = false;
|
||||
}
|
||||
this.statusBarItem.command = 'texinfo.indicator.click';
|
||||
this.statusBarItem.text = `${icon} GNU Texinfo ${version}`;
|
||||
this.statusBarItem.tooltip = tooltip;
|
||||
this._statusBarItem.command = 'texinfo.indicator.click';
|
||||
this._statusBarItem.text = `${icon} GNU Texinfo ${version}`;
|
||||
this._statusBarItem.tooltip = tooltip;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,20 +24,24 @@ import * as vscode from 'vscode';
|
|||
/**
|
||||
* Logger which prints message to VSCode output channel.
|
||||
*/
|
||||
export default class Logger implements vscode.Disposable {
|
||||
|
||||
export default class Logger implements vscode.Disposable
|
||||
{
|
||||
log(message: string) {
|
||||
const dateTime = new Date().toLocaleString(undefined, { hour12: false });
|
||||
this.outputChannel.appendLine(`[ ${dateTime} ]\n${message}`);
|
||||
const dateTime = new Date().toLocaleString(
|
||||
undefined,
|
||||
{ hour12: false }
|
||||
);
|
||||
this._outputChannel.appendLine(`[ ${dateTime} ]\n${message}`);
|
||||
}
|
||||
|
||||
show() {
|
||||
this.outputChannel.show(true);
|
||||
this._outputChannel.show(true);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.outputChannel.dispose();
|
||||
this._outputChannel.dispose();
|
||||
}
|
||||
|
||||
private readonly outputChannel = vscode.window.createOutputChannel('Texinfo');
|
||||
private readonly _outputChannel
|
||||
= vscode.window.createOutputChannel('Texinfo');
|
||||
}
|
||||
|
|
|
@ -26,75 +26,80 @@ import * as vscode from 'vscode';
|
|||
*
|
||||
* See the `contributes.configuration` entry in package.json for details.
|
||||
*/
|
||||
export default class Options {
|
||||
|
||||
export default class Options
|
||||
{
|
||||
get enableSnippets() {
|
||||
return this.getBoolean('completion.enableSnippets');
|
||||
return this._getBoolean('completion.enableSnippets');
|
||||
}
|
||||
|
||||
get hideSnippetCommands() {
|
||||
return this.getBoolean('completion.hideSnippetCommands');
|
||||
return this._getBoolean('completion.hideSnippetCommands');
|
||||
}
|
||||
|
||||
get noWarnings() {
|
||||
return this.getBoolean('diagnosis.noWarnings');
|
||||
return this._getBoolean('diagnosis.noWarnings');
|
||||
}
|
||||
|
||||
get enableCodeLens() {
|
||||
return this.getBoolean('enableCodeLens');
|
||||
return this._getBoolean('enableCodeLens');
|
||||
}
|
||||
|
||||
get makeinfo() {
|
||||
return this.getString('makeinfo');
|
||||
return this._getString('makeinfo');
|
||||
}
|
||||
|
||||
get customCSS() {
|
||||
return this.getString('preview.customCSS');
|
||||
return this._getString('preview.customCSS');
|
||||
}
|
||||
|
||||
get errorLimit() {
|
||||
return this.getNumber('preview.errorLimit');
|
||||
return this._getNumber('preview.errorLimit');
|
||||
}
|
||||
|
||||
get includePaths() {
|
||||
return this.getArray('preview.includePaths');
|
||||
return this._getArray('preview.includePaths');
|
||||
}
|
||||
|
||||
get maxSize() {
|
||||
return this.getNumber('preview.maxSize') * 1024 * 1024;
|
||||
return this._getNumber('preview.maxSize') * 1024 * 1024;
|
||||
}
|
||||
|
||||
get noHeaders() {
|
||||
return this.getBoolean('preview.noHeaders');
|
||||
return this._getBoolean('preview.noHeaders');
|
||||
}
|
||||
|
||||
get noNumberSections() {
|
||||
return this.getBoolean('preview.noNumberSections');
|
||||
return this._getBoolean('preview.noNumberSections');
|
||||
}
|
||||
|
||||
get noValidation() {
|
||||
return this.getBoolean('preview.noValidation');
|
||||
return this._getBoolean('preview.noValidation');
|
||||
}
|
||||
|
||||
get variables() {
|
||||
return this.getArray('preview.variables');
|
||||
return this._getArray('preview.variables');
|
||||
}
|
||||
|
||||
private readonly configuration = vscode.workspace.getConfiguration('texinfo');
|
||||
|
||||
private getArray(section: string): readonly string[] {
|
||||
return this.configuration.get(section, []);
|
||||
get customizationVariables() {
|
||||
return this._getArray('preview.customizationVariables');
|
||||
}
|
||||
|
||||
private getBoolean(section: string) {
|
||||
return this.configuration.get(section, false);
|
||||
private readonly _configuration
|
||||
= vscode.workspace.getConfiguration('texinfo');
|
||||
|
||||
private _getArray(section: string): readonly string[] {
|
||||
return this._configuration.get(section, []);
|
||||
}
|
||||
|
||||
private getNumber(section: string) {
|
||||
return this.configuration.get(section, 0);
|
||||
private _getBoolean(section: string) {
|
||||
return this._configuration.get(section, false);
|
||||
}
|
||||
|
||||
private getString(section: string) {
|
||||
return this.configuration.get(section, '');
|
||||
private _getNumber(section: string) {
|
||||
return this._configuration.get(section, 0);
|
||||
}
|
||||
|
||||
private _getString(section: string) {
|
||||
return this._configuration.get(section, '');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,18 @@ import GlobalContext from '../global_context';
|
|||
/**
|
||||
* Provide code lenses for Texinfo document.
|
||||
*/
|
||||
export default class CodeLensProvider implements vscode.CodeLensProvider {
|
||||
|
||||
export default class CodeLensProvider implements vscode.CodeLensProvider
|
||||
{
|
||||
provideCodeLenses(document: vscode.TextDocument) {
|
||||
if (!this.globalContext.options.enableCodeLens) return undefined;
|
||||
if (!this.globalContext.indicator.canDisplayPreview) return undefined;
|
||||
return this.globalContext.contextMapping.getDocumentContext(document).foldingRange.nodeValues;
|
||||
if (!this._globalContext.options.enableCodeLens) {
|
||||
return undefined;
|
||||
}
|
||||
if (!this._globalContext.indicator.canDisplayPreview) {
|
||||
return undefined;
|
||||
}
|
||||
return this._globalContext.contextMapping
|
||||
.getDocumentContext(document).foldingRange.nodeValues;
|
||||
}
|
||||
|
||||
constructor(private readonly globalContext: GlobalContext) {}
|
||||
constructor(private readonly _globalContext: GlobalContext) {}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,11 +25,13 @@ import GlobalContext from '../global_context';
|
|||
/**
|
||||
* Provide document symbol information for Texinfo documents.
|
||||
*/
|
||||
export default class DocumentSymbolProvider implements vscode.DocumentSymbolProvider {
|
||||
|
||||
export default class DocumentSymbolProvider
|
||||
implements vscode.DocumentSymbolProvider
|
||||
{
|
||||
provideDocumentSymbols(document: vscode.TextDocument) {
|
||||
return this.globalContext.contextMapping.getDocumentContext(document).documentSymbol.documentSymbols;
|
||||
return this._globalContext.contextMapping
|
||||
.getDocumentContext(document).documentSymbol.documentSymbols;
|
||||
}
|
||||
|
||||
constructor(private readonly globalContext: GlobalContext) {}
|
||||
constructor(private readonly _globalContext: GlobalContext) {}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,13 @@ import GlobalContext from '../global_context';
|
|||
/**
|
||||
* Provide folding range info for Texinfo documents.
|
||||
*/
|
||||
export default class FoldingRangeProvider implements vscode.FoldingRangeProvider {
|
||||
|
||||
export default class FoldingRangeProvider
|
||||
implements vscode.FoldingRangeProvider
|
||||
{
|
||||
provideFoldingRanges(document: vscode.TextDocument) {
|
||||
return this.globalContext.contextMapping.getDocumentContext(document).foldingRange.foldingRanges;
|
||||
return this._globalContext.contextMapping
|
||||
.getDocumentContext(document).foldingRange.foldingRanges;
|
||||
}
|
||||
|
||||
constructor(private readonly globalContext: GlobalContext) {}
|
||||
constructor(private readonly _globalContext: GlobalContext) {}
|
||||
}
|
||||
|
|
|
@ -23,52 +23,76 @@ import * as path from 'path';
|
|||
import * as vscode from 'vscode';
|
||||
import Logger from '../logger';
|
||||
import Options from '../options';
|
||||
import { exec } from './misc';
|
||||
import { exec, normalizePath } from './misc';
|
||||
import { Operator } from './types';
|
||||
|
||||
/**
|
||||
* Converter which converts file from Texinfo to other formats.
|
||||
*/
|
||||
export default class Converter {
|
||||
|
||||
export default class Converter
|
||||
{
|
||||
async toHTML(imgTransformer: Operator<vscode.Uri>, insertScript?: string) {
|
||||
const newPath = imgTransformer(vscode.Uri.file(path.dirname(this.path))).toString() + '/';
|
||||
const options = ['-o-', '--no-split', '--html', `--error-limit=${this.options.errorLimit}`,
|
||||
`--init-file=${this.initFile}`, '-D', `__vscode_texinfo_image_uri_base ${newPath}`];
|
||||
this.options.noHeaders && options.push('--no-headers');
|
||||
this.options.noNumberSections && options.push('--no-number-sections');
|
||||
this.options.noValidation && options.push('--no-validate');
|
||||
this.options.noWarnings && options.push('--no-warn');
|
||||
insertScript !== undefined && options.push('-c', `EXTRA_HEAD <script>${insertScript}</script>`);
|
||||
this.addIncludePaths(this.options.includePaths, options);
|
||||
this.defineVariables(this.options.variables, options);
|
||||
this.includeCustomCSS(this.options.customCSS, options);
|
||||
return await exec(this.options.makeinfo, options.concat(this.path), this.options.maxSize);
|
||||
const pathUri = vscode.Uri.file(path.dirname(this._pathName) + '/');
|
||||
const newPath = normalizePath(imgTransformer(pathUri).toString());
|
||||
const options = ['-o-', '--no-split', '--html',
|
||||
`--error-limit=${this._options.errorLimit}`,
|
||||
`--init-file=${this._initFile}`,
|
||||
'-D', `__vscode_texinfo_image_uri_base ${newPath}`,
|
||||
];
|
||||
this._options.noHeaders && options.push('--no-headers');
|
||||
this._options.noNumberSections && options.push('--no-number-sections');
|
||||
this._options.noValidation && options.push('--no-validate');
|
||||
this._options.noWarnings && options.push('--no-warn');
|
||||
if (insertScript !== undefined) {
|
||||
options.push('-c', `EXTRA_HEAD <script>${insertScript}</script>`);
|
||||
}
|
||||
this._addIncludePaths(this._options.includePaths, options);
|
||||
this._defineVariables(this._options.variables, options);
|
||||
this._setCustomizationVariables(
|
||||
this._options.customizationVariables, options);
|
||||
this._includeCustomCSS(this._options.customCSS, options);
|
||||
return await exec(
|
||||
this._options.makeinfo,
|
||||
options.concat(normalizePath(this._pathName)),
|
||||
this._options.maxSize,
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly path: string,
|
||||
private readonly initFile: string,
|
||||
private readonly options: Options,
|
||||
private readonly logger: Logger,
|
||||
private readonly _pathName: string,
|
||||
private readonly _initFile: string,
|
||||
private readonly _options: Options,
|
||||
private readonly _logger: Logger,
|
||||
) {}
|
||||
|
||||
private addIncludePaths(paths: readonly string[], options: string[]) {
|
||||
private _addIncludePaths(paths: readonly string[], options: string[]) {
|
||||
if (paths.length === 0) {
|
||||
return;
|
||||
}
|
||||
const separator = process.platform === 'win32' ? ';' : ':';
|
||||
options.push('-I', paths.join(separator));
|
||||
}
|
||||
|
||||
private defineVariables(variables: readonly string[], options: string[]) {
|
||||
private _defineVariables(variables: readonly string[], options: string[]) {
|
||||
variables.forEach(varName => options.push('-D', varName));
|
||||
}
|
||||
|
||||
private includeCustomCSS(cssFileURI: string, options: string[]) {
|
||||
if (!cssFileURI) return;
|
||||
private _setCustomizationVariables(
|
||||
variables: readonly string[],
|
||||
options: string[],
|
||||
) {
|
||||
variables.forEach(varName => options.push('-c', varName));
|
||||
}
|
||||
|
||||
private _includeCustomCSS(cssFileURI: string, options: string[]) {
|
||||
if (!cssFileURI) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const uri = vscode.Uri.parse(cssFileURI, true);
|
||||
switch (uri.scheme) {
|
||||
case 'file':
|
||||
options.push(`--css-include=${uri.path}`);
|
||||
options.push(`--css-include=${normalizePath(uri.fsPath)}`);
|
||||
break;
|
||||
case 'http':
|
||||
case 'https':
|
||||
|
@ -78,7 +102,8 @@ export default class Converter {
|
|||
throw URIError;
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.log(`Cannot load custom CSS. Invalid URI: '${cssFileURI}'`);
|
||||
this._logger
|
||||
.log(`Cannot load custom CSS. Invalid URI: '${cssFileURI}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,20 @@
|
|||
*/
|
||||
|
||||
import * as child_process from 'child_process';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExecResult } from './types';
|
||||
|
||||
/**
|
||||
* Escape string to match verbatim in regular expression.
|
||||
*
|
||||
* @param str The string to be escaped.
|
||||
* @returns The escaped string.
|
||||
*/
|
||||
export function escapeStringForRegExp(str: string) {
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute command and fetch output.
|
||||
*
|
||||
|
@ -32,9 +43,18 @@ import { ExecResult } from './types';
|
|||
* @returns The output data, or `undefined` if execution fails.
|
||||
*/
|
||||
export function exec(path: string, args: string[], maxBuffer: number) {
|
||||
return new Promise<ExecResult>(resolve => child_process.execFile(path, args,
|
||||
{ env: { ...process.env, LC_MESSAGES: 'en_US' }, maxBuffer: maxBuffer }, (error, stdout, stderr) =>
|
||||
resolve(error ? { error: stderr ? stderr : error.message } : { data: stdout, error: stderr })));
|
||||
return new Promise<ExecResult>(
|
||||
resolve => child_process.execFile(path, args,
|
||||
{
|
||||
env: { ...process.env, LC_MESSAGES: 'en_US.UTF-8' },
|
||||
maxBuffer: maxBuffer,
|
||||
},
|
||||
(error, stdout, stderr) => resolve(error
|
||||
? { error: stderr ? stderr : error.message }
|
||||
: { data: stdout, error: stderr }
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +66,8 @@ export function exec(path: string, args: string[], maxBuffer: number) {
|
|||
* @returns Whether the user clicked the button.
|
||||
*/
|
||||
export async function prompt(message: string, label: string, error = false) {
|
||||
const func = error ? vscode.window.showErrorMessage : vscode.window.showInformationMessage;
|
||||
const func = error ?
|
||||
vscode.window.showErrorMessage : vscode.window.showInformationMessage;
|
||||
return label === await func(message, label);
|
||||
}
|
||||
|
||||
|
@ -68,7 +89,8 @@ export function lineNumToRange(startLine: number, endLine = startLine) {
|
|||
* @param charCode ASCII code of character.
|
||||
*/
|
||||
export function isAlpha(charCode: number) {
|
||||
return charCode >= 97 && charCode <= 122 || charCode >= 65 && charCode <= 90;
|
||||
return (charCode >= 97 && charCode <= 122)
|
||||
|| (charCode >= 65 && charCode <= 90);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,16 +99,17 @@ export function isAlpha(charCode: number) {
|
|||
* @param charCode ASCII code of character.
|
||||
*/
|
||||
export function isAlnum(charCode: number) {
|
||||
return isAlpha(charCode) || charCode >= 48 && charCode <= 57;
|
||||
return isAlpha(charCode) || (charCode >= 48 && charCode <= 57);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get corresponding HTML cross-reference name by node name.
|
||||
*
|
||||
* See section *HTML Cross-reference Node Name Expansion* in the Texinfo manual.
|
||||
* See section *HTML Cross-reference Node Name Expansion* in the
|
||||
* GNU Texinfo manual.
|
||||
*
|
||||
* TODO: Node name is not displayed verbatim, leading to wrong HTML xref when containing commands.
|
||||
* Fix this when migrating to LSP.
|
||||
* TODO: Node name is not displayed verbatim, leading to wrong HTML xref when
|
||||
* containing commands. Fix this when migrating to LSP.
|
||||
*
|
||||
* @param nodeName
|
||||
*/
|
||||
|
@ -100,5 +123,22 @@ export function getNodeHtmlRef(nodeName: string) {
|
|||
.join(''))
|
||||
.join('-');
|
||||
const firstCharCode = result.charCodeAt(0);
|
||||
return isAlpha(firstCharCode) ? result : 'g_t_00' + firstCharCode.toString(16) + result.substring(1);
|
||||
return isAlpha(firstCharCode)
|
||||
? result
|
||||
: 'g_t_00' + firstCharCode.toString(16) + result.substring(1);
|
||||
}
|
||||
|
||||
export function normalizePath(pathName: string) {
|
||||
pathName = path.normalize(pathName);
|
||||
if (process.platform === 'win32') {
|
||||
// On Windows, when passing the path of input file to makeinfo,
|
||||
// using backslashes in path name breaks some other command line
|
||||
// options (notably, -I).
|
||||
// Not sure if this is a bug of makeinfo, or perl, or neither.
|
||||
//
|
||||
// TODO: We should look into this issue sometime later.
|
||||
return pathName.replace(/\\/g, '/');
|
||||
} else {
|
||||
return pathName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,19 +21,33 @@
|
|||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export type CompletionItem = vscode.CompletionItem & { snippet?: boolean };
|
||||
export type CompletionItem = vscode.CompletionItem & {
|
||||
snippet?: boolean,
|
||||
};
|
||||
|
||||
export type ExecResult = { data?: string, error: string };
|
||||
export type ExecResult = {
|
||||
data?: string,
|
||||
error: string,
|
||||
};
|
||||
|
||||
export type FoldingRange = vscode.FoldingRange & { name: string, detail: string };
|
||||
export type FoldingRange = vscode.FoldingRange & {
|
||||
name: string,
|
||||
detail: string,
|
||||
};
|
||||
|
||||
export type NamedLine = { name: string, line: number };
|
||||
export type NamedLine = {
|
||||
name: string,
|
||||
line: number,
|
||||
};
|
||||
|
||||
export type Operator<T> = (arg: T) => T;
|
||||
|
||||
export type Optional<T> = T | undefined;
|
||||
|
||||
export type Range = { start: number, end: number };
|
||||
export type Range = {
|
||||
start: number,
|
||||
end: number,
|
||||
};
|
||||
|
||||
export function isDefined<T>(value: Optional<T>): value is T {
|
||||
return value !== undefined;
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
*/
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"target": "ES2019",
|
||||
"target": "ES2021",
|
||||
"outDir": "out",
|
||||
"esModuleInterop": true,
|
||||
"strictNullChecks": true,
|
||||
|
|
|
@ -19,13 +19,15 @@ const config: webpack.Configuration = {
|
|||
output: {
|
||||
path: path.resolve(__dirname, 'out'),
|
||||
filename: 'extension.js',
|
||||
libraryTarget: 'commonjs2',
|
||||
library: {
|
||||
type: "commonjs2",
|
||||
},
|
||||
devtoolModuleFilenameTemplate: '../[resource-path]',
|
||||
},
|
||||
devtool: isProduction ? false : 'source-map',
|
||||
optimization: {
|
||||
concatenateModules: true,
|
||||
minimize: true,
|
||||
minimize: isProduction,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false,
|
||||
|
@ -39,6 +41,9 @@ const config: webpack.Configuration = {
|
|||
},
|
||||
mangle: {
|
||||
module: true,
|
||||
properties: {
|
||||
regex: /^_/,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue