You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@codemirror/lang-python

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lang-python - npm Package Compare versions

Comparing version

to
6.1.7

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 6.1.7 (2025-01-18)
### Bug fixes
Properly indent match/case statements.
## 6.1.6 (2024-04-29)

@@ -2,0 +8,0 @@

20

dist/index.js

@@ -207,3 +207,3 @@ import { parser } from '@lezer/python';

}
else if (before.name == "Body") {
else if (before.name == "Body" || before.name == "MatchBody") {
if (context.baseIndentFor(before) + context.unit <= lineIndent)

@@ -213,2 +213,5 @@ found = before;

}
else if (before.name == "MatchClause") {
node = before;
}
else if (before.type.is("Statement")) {

@@ -236,3 +239,3 @@ node = before;

// level
if (/^\s*(else:|elif |except |finally:)/.test(context.textAfter) && context.lineIndent(context.pos, -1) > base)
if (/^\s*(else:|elif |except |finally:|case\s+[^=:]+:)/.test(context.textAfter) && context.lineIndent(context.pos, -1) > base)
return null;

@@ -256,5 +259,15 @@ return base + context.unit;

},
MatchBody: context => {
var _a;
let inner = innerBody(context);
return (_a = indentBody(context, inner || context.node)) !== null && _a !== void 0 ? _a : context.continue();
},
IfStatement: cx => /^\s*(else:|elif )/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
"ForStatement WhileStatement": cx => /^\s*else:/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
TryStatement: cx => /^\s*(except |finally:|else:)/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
MatchStatement: cx => {
if (/^\s*case /.test(cx.textAfter))
return cx.baseIndent + cx.unit;
return cx.continue();
},
"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression": /*@__PURE__*/delimitedIndent({ closing: ")" }),

@@ -283,3 +296,4 @@ "DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression": /*@__PURE__*/delimitedIndent({ closing: "}" }),

commentTokens: { line: "#" },
indentOnInput: /^\s*([\}\]\)]|else:|elif |except |finally:)$/
// Indent logic logic are triggered upon below input patterns
indentOnInput: /^\s*([\}\]\)]|else:|elif |except |finally:|case\s+[^:]*:?)$/,
}

@@ -286,0 +300,0 @@ });

2

package.json
{
"name": "@codemirror/lang-python",
"version": "6.1.6",
"version": "6.1.7",
"description": "Python language support for the CodeMirror code editor",

@@ -5,0 +5,0 @@ "scripts": {

@@ -22,5 +22,30 @@ <!-- NOTE: README.md is generated from src/README.md -->

## Usage
```javascript
import {EditorView, basicSetup} from "codemirror"
import {python} from "@codemirror/lang-python"
const view = new EditorView({
parent: document.body,
doc: `print("Hello world")`,
extensions: [basicSetup, python()]
})
```
# API Reference
<dl>
<dt id="user-content-python">
<code><strong><a href="#user-content-python">python</a></strong>() → <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt>
<dd><p>Python language support.</p>
</dd>
<dt id="user-content-pythonlanguage">
<code><strong><a href="#user-content-pythonlanguage">pythonLanguage</a></strong>: <a href="https://codemirror.net/docs/ref#language.LRLanguage">LRLanguage</a></code></dt>
<dd><p>A language provider based on the <a href="https://github.com/lezer-parser/python">Lezer Python
parser</a>, extended with
highlighting and indentation information.</p>
</dd>
<dt id="user-content-globalcompletion">

@@ -37,14 +62,2 @@ <code><strong><a href="#user-content-globalcompletion">globalCompletion</a></strong>: <a href="https://codemirror.net/docs/ref#autocomplete.CompletionSource">CompletionSource</a></code></dt>

</dd>
<dt id="user-content-pythonlanguage">
<code><strong><a href="#user-content-pythonlanguage">pythonLanguage</a></strong>: <a href="https://codemirror.net/docs/ref#language.LRLanguage">LRLanguage</a></code></dt>
<dd><p>A language provider based on the <a href="https://github.com/lezer-parser/python">Lezer Python
parser</a>, extended with
highlighting and indentation information.</p>
</dd>
<dt id="user-content-python">
<code><strong><a href="#user-content-python">python</a></strong>() → <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt>
<dd><p>Python language support.</p>
</dd>
</dl>
</dl>

Sorry, the diff of this file is not supported yet