Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the block comment work in Python (and other languages without block comments) #16212

Open
krassowski opened this issue Apr 20, 2024 · 5 comments

Comments

@krassowski
Copy link
Member

krassowski commented Apr 20, 2024

Problem

  • CodeMirror does not implement block comment for Python language which means executing block comment shortcut is no-op in Python and users think it is broken
  • Python does not define block comment syntax, although """ is de facto standard substitute as blessed by BDFL
  • we want to keep separate block and line comments shortcuts for users using languages which do have as separate block comments

Proposed Solution

Either or both:

  • (a) use pythonLanguage.data.of({commentTokens: ...}) to add """ as block comment for Python - this only helps for Python
  • (b) replace uses of toggleBlockComment with a composite command which tries to run toggleBlockComment first and toggleComment second if the former did not succeed (or check if language data have commentTokens.block defined)

Additional context

See discussion in upstream issue codemirror/dev#1372 - upstream will not include that command nor the """ syntax for Python so it is up to JupyterLab to implement it.

@krassowski
Copy link
Member Author

These lines would need to be modified for (b):

caption: trans.__(
'Toggles block commends in languages which support it (e.g. C, JavaScript)'
),
execute: () => {
const view = findEditorView();
if (!view) {
return;
}
toggleBlockComment(view);
},

@krassowski
Copy link
Member Author

These lines would need to be modified for (a):

const m = await import('@codemirror/lang-python');
return new LanguageSupport(
m.pythonLanguage,
pythonBuiltin(m.pythonLanguage)
);
}
},
{
name: 'ipython',
displayName: trans.__('ipython'),
mime: 'text/x-ipython',
async load() {
// FIXME Restore '?' operator - using the default python LanguageSupport allows
// to activate feature such as code folding.
// return Promise.resolve(legacy(mkPython({ singleOperators: /\?/ })));
const m = await import('@codemirror/lang-python');
return new LanguageSupport(
m.pythonLanguage,
pythonBuiltin(m.pythonLanguage)
);

@krassowski
Copy link
Member Author

Some research is needed on (a) - what other other IDEs do? Do they use """ syntax for block comment, or do they fall back to multiple # ?

@smbrett
Copy link

smbrett commented Apr 22, 2024

Hi I would like to work on this issue.

@krassowski
Copy link
Member Author

Please do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants