## Summary of the Pull Request Accumulated information from internal transition about the modules development, and reworked it to be added in dev docs. Also the dev docs intself was restructured to be more organized. New pages was verified by transition team. ## PR Checklist - [x] **Dev docs:** Added/updated --------- Co-authored-by: Zhaopeng Wang (from Dev Box) <zhaopengwang@microsoft.com> Co-authored-by: Hao Liu <liuhao3418@gmail.com> Co-authored-by: Peiyao Zhao <105847726+zhaopy536@users.noreply.github.com> Co-authored-by: Mengyuan <162882040+chenmy77@users.noreply.github.com> Co-authored-by: zhaopeng wang <33367956+wang563681252@users.noreply.github.com> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com>
5.2 KiB
FilePreviewCommon
This project contains common code used for previewing and displaying files.
Monaco preview
Monaco preview enables to display developer files. It is based on Microsoft's Monaco Editor which is maintained by the Visual Studio Code team.
This previewer is used for the File Explorer Dev File Previewer, as well as PowerToys Peek.
For a general overview of how Monaco is used in PowerToys, see the Monaco Editor documentation.
Update Monaco Editor
- Download Monaco editor with npm: Run
npm i monaco-editorin the command prompt. - Delete everything except the
minfolder (the minimised code) from the downloaded files. - Copy the
minfolder into the/src/Monaco/monacoSRCfolder of the PowerToys project. - Generate the JSON file as described in the generate monaco_languages.json file section.
Add a new language definition
As an example on how to add a new language definition you can look at the one for registry files.
- Add the new language definition (written with Monarch) as a new file to the folder containing Monaco custom languages (Remember the file name and the string you used for "idDefinition" as you need it later.). The file should be formatted like in the example below. (Please change
idDefinitionto the name of your language.)
export function idDefinition() {
return {
...
}
}
- Add the following line to the
monacoSpecialLanguages.jsfile, after the other import statements:
import { idDefinition } from './customLanguages/file.js';
Replace file.js with the name of your definition file from step 1. Please replace idDefinition with the string you used in step 1.
- In the
monacoSpecialLanguages.jsfile add the following line into theregisterAdditionalLanguagesfunction:
registerAdditionalNewLanguage("id", [".fileExtension"], idDefinition(), monaco)
Replace id and idDefinition with your id and string used in step 1. Replace fileExtension with a set of file extensions you want the language to register to.
- The id can be anything. Recommended is one of the file extensions. For example "php" or "reg".
- In case you wish to add a custom color for a token, you can do so by adding the following line to
customTokenThemeRules.js:
{token: 'token-name', foreground: 'ff0000'}
Replace
token-namewith the name of the token andff0000with the hex code of the desired color. Note: you can also specify abackgroundand afontStyleattribute for your token.
- Keep in mind that these rules apply to all languages. Therefore, you should not change the colors of any default tokens. Instead, create new tokens specific to the language you are adding.
- Execute the steps described in the monaco_languages.json section.
Add a new file extension to an existing language
- In the
monacoSpecialLanguages.jsfile add the following line to theregisterAdditionalLanguagesfunction. (existingIdis the id of the language you want to add the extension to. You can find these id's in themonaco_languages.jsonfile):
registerAdditionalLanguage("id", [".fileExtension"], "existingId", monaco)
- If for instance you want to add more extensions to the php language set the id to
phpExtand the existingId tophp.
-
Copy the existing language definition into the
languageDefinitionsfunction in the same file. You can find the existing definitions in the following folder:/src/Monaco/monacoSRC/min/vs/basic-languages/. -
Execute the steps described in the monaco_languages.json section.
monaco_languages.json
monaco_languages.json contains all extensions and IDs for the languages supported by Monaco. The MonacoHelper class and the installer are using this file to register preview handlers for the defined extensions.
After updating Monaco Editor and/or adding a new language you should update the monaco_languages.json file.
- Run the
generateLanguagesJson.htmlfile on a local webserver (as webbrowsers will block certain needed features when running the file locally.)
- This can for example be achieved by using the Preview Server extension for Visual Studio Code: Open the file in Visual Studio Code, right click in the code editor and select
vscode-preview-server: Launch on browser. The file will be opened in a browser.
- The browser will download the new
monaco_languages.jsonfile - Replace the old file with the newly downloaded one in the source code folder.