Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
erp5
Commits
b58c095c
Commit
b58c095c
authored
Nov 08, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monaco_editor: enable formatting provider for python
This makes "Format Document" / "Format Selection" work.
parent
6efc45bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
1 deletion
+69
-1
bt5/erp5_monaco_editor/SkinTemplateItem/portal_skins/erp5_monaco_editor/monaco-editor.gadget.js.js
...ortal_skins/erp5_monaco_editor/monaco-editor.gadget.js.js
+69
-1
No files found.
bt5/erp5_monaco_editor/SkinTemplateItem/portal_skins/erp5_monaco_editor/monaco-editor.gadget.js.js
View file @
b58c095c
...
@@ -181,7 +181,8 @@
...
@@ -181,7 +181,8 @@
})
})
.
onStateChange
(
function
(
modification_dict
)
{
.
onStateChange
(
function
(
modification_dict
)
{
var
queue
=
new
RSVP
.
Queue
();
var
queue
=
new
RSVP
.
Queue
(),
gadget
=
this
;
if
(
modification_dict
.
hasOwnProperty
(
'
value
'
))
{
if
(
modification_dict
.
hasOwnProperty
(
'
value
'
))
{
// Do not notify the UI when initializing the value
// Do not notify the UI when initializing the value
this
.
state
.
ignoredChangeDuringInitialization
=
true
;
this
.
state
.
ignoredChangeDuringInitialization
=
true
;
...
@@ -266,6 +267,73 @@
...
@@ -266,6 +267,73 @@
}
}
if
(
this
.
state
.
model_language
===
'
python
'
)
{
if
(
this
.
state
.
model_language
===
'
python
'
)
{
this
.
editor
.
getModel
().
onDidChangeContent
(
this
.
runPyLint
.
bind
(
this
));
this
.
editor
.
getModel
().
onDidChangeContent
(
this
.
runPyLint
.
bind
(
this
));
const
yapfDocumentFormattingProvider
=
{
_provideFormattingEdits
:
function
(
model
,
range
,
options
,
token
)
{
const
controller
=
new
AbortController
();
token
.
onCancellationRequested
(()
=>
{
controller
.
abort
();
});
const
data
=
new
FormData
();
data
.
append
(
'
data
'
,
JSON
.
stringify
({
code
:
model
.
getValue
(),
range
:
range
})
);
return
fetch
(
gadget
.
state
.
language_support_url
+
'
/ERP5Site_formatPythonSourceCode
'
,
{
method
:
'
POST
'
,
body
:
data
,
signal
:
controller
.
signal
,
}
)
.
then
((
response
)
=>
response
.
json
())
.
then
(
(
data
)
=>
{
if
(
data
.
error
)
{
this
.
editor
.
revealLine
(
data
.
error_line
);
return
;
}
if
(
data
.
changed
)
{
return
[
{
range
:
model
.
getFullModelRange
(),
text
:
data
.
formatted_code
,
},
];
}
},
(
e
)
=>
{
if
(
!
(
e
instanceof
DOMException
)
/* AbortError */
)
{
throw
e
;
}
/* ignore aborted requests */
}
);
},
provideDocumentRangeFormattingEdits
:
function
(
model
,
range
,
options
,
token
)
{
return
this
.
_provideFormattingEdits
(
model
,
range
,
options
,
token
);
},
provideDocumentFormattingEdits
:
function
(
model
,
options
,
token
)
{
return
this
.
_provideFormattingEdits
(
model
,
null
,
options
,
token
);
},
};
monaco
.
languages
.
registerDocumentFormattingEditProvider
(
'
python
'
,
yapfDocumentFormattingProvider
);
monaco
.
languages
.
registerDocumentRangeFormattingEditProvider
(
'
python
'
,
yapfDocumentFormattingProvider
);
this
.
runPyLint
();
this
.
runPyLint
();
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment