editor: copy python language configuration

This copies the language configuration from https://github.com/microsoft/monaco-languages/blob/d7cc098c481059f63d51ce3753975c8ca8ab6030/src/python/python.ts

This fixes a number of editor features, like auto-indent.

Fixes: https://github.com/pybricks/pybricks-code/issues/470
This commit is contained in:
David Lechner
2021-07-08 15:55:50 -05:00
parent 4b0dc90e8d
commit ad948dc152
3 changed files with 50 additions and 1 deletions
+4
View File
@@ -7,6 +7,9 @@
### Changed
- Changed snippet (autocomplete) content and behavior [issue#471].
### Fixed
- Fixed auto-indent not working [issue#470].
## [1.1.0-beta.2] - 2021-07-06
## Changed
@@ -38,6 +41,7 @@ Prerelease changes are documented at [support#48].
<!-- let's try to keep this list sorted -->
[issue#470]: https://github.com/pybricks/pybricks-code/issues/470
[issue#471]: https://github.com/pybricks/pybricks-code/issues/471
[support#48]: https://github.com/pybricks/support/issues/48
[support#378]: https://github.com/pybricks/support/issues/378
+4
View File
@@ -42,6 +42,10 @@ monaco.languages.register({ id: pybricksMicroPythonId });
const toDispose = new Array<IDisposable>();
toDispose.push(
monaco.languages.setLanguageConfiguration(
pybricksMicroPythonId,
pybricksMicroPython.conf,
),
monaco.languages.setMonarchTokensProvider(
pybricksMicroPythonId,
pybricksMicroPython.language,
+42 -1
View File
@@ -1,4 +1,4 @@
// Copied from https://github.com/microsoft/monaco-languages/blob/main/src/python/python.ts
// Copied from https://github.com/microsoft/monaco-languages/blob/d7cc098c481059f63d51ce3753975c8ca8ab6030/src/python/python.ts
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7,6 +7,47 @@
import { monaco } from 'react-monaco-editor';
export const conf: monaco.languages.LanguageConfiguration = {
comments: {
lineComment: '#',
blockComment: ["'''", "'''"],
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: "'", close: "'", notIn: ['string', 'comment'] },
],
surroundingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: "'", close: "'" },
],
onEnterRules: [
{
beforeText: new RegExp(
'^\\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\\s*$',
),
action: { indentAction: monaco.languages.IndentAction.Indent },
},
],
folding: {
offSide: true,
markers: {
start: new RegExp('^\\s*#region\\b'),
end: new RegExp('^\\s*#endregion\\b'),
},
},
};
export const language = <monaco.languages.IMonarchLanguage>{
defaultToken: '',
tokenPostfix: '.python',