mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user