@codemirror/lang-python
Advanced tools
Comparing version 0.18.0 to 0.18.1
@@ -0,3 +1,17 @@ | ||
## 0.18.1 (2021-07-20) | ||
### Bug fixes | ||
Fix highlighting of property names. Improve indentation support | ||
Don't deindent when pressing enter at the end of the document. | ||
Properly indent else/elif/except syntax. | ||
## 0.18.0 (2021-03-03) | ||
### Breaking changes | ||
Update dependencies to 0.18. | ||
## 0.17.2 (2021-01-12) | ||
@@ -4,0 +18,0 @@ |
import { LezerLanguage, LanguageSupport } from '@codemirror/language'; | ||
/** | ||
A language provider based on the [Lezer Python | ||
parser](https://github.com/lezer-parser/python), extended with | ||
highlighting and indentation information. | ||
*/ | ||
declare const pythonLanguage: LezerLanguage; | ||
/** | ||
Python language support. | ||
*/ | ||
declare function python(): LanguageSupport; | ||
export { python, pythonLanguage }; |
@@ -5,15 +5,29 @@ import { parser } from 'lezer-python'; | ||
/// A language provider based on the [Lezer Python | ||
/// parser](https://github.com/lezer-parser/python), extended with | ||
/// highlighting and indentation information. | ||
const pythonLanguage = LezerLanguage.define({ | ||
parser: parser.configure({ | ||
/** | ||
A language provider based on the [Lezer Python | ||
parser](https://github.com/lezer-parser/python), extended with | ||
highlighting and indentation information. | ||
*/ | ||
const pythonLanguage = /*@__PURE__*/LezerLanguage.define({ | ||
parser: /*@__PURE__*/parser.configure({ | ||
props: [ | ||
indentNodeProp.add({ | ||
Body: continuedIndent() | ||
/*@__PURE__*/indentNodeProp.add({ | ||
Body: /*@__PURE__*/continuedIndent({ except: /^\s*(else|elif|except|finally)\b/ }), | ||
Script: context => { | ||
if (context.pos + /\s*/.exec(context.textAfter)[0].length < context.node.to) | ||
return context.continue(); | ||
let endBody = null; | ||
for (let cur = context.node;;) { | ||
let last = cur.lastChild; | ||
if (!last || last.type.name != "Body" || last.to != cur.to) | ||
break; | ||
endBody = cur = last; | ||
} | ||
return endBody ? context.lineIndent(context.state.doc.lineAt(endBody.from)) + context.unit : null; | ||
} | ||
}), | ||
foldNodeProp.add({ | ||
/*@__PURE__*/foldNodeProp.add({ | ||
"Body ArrayExpression DictionaryExpression": foldInside | ||
}), | ||
styleTags({ | ||
/*@__PURE__*/styleTags({ | ||
"async '*' '**' FormatConversion": tags.modifier, | ||
@@ -28,11 +42,11 @@ "for while if elif else try except finally return raise break continue with pass assert await yield": tags.controlKeyword, | ||
VariableName: tags.variableName, | ||
"CallExpression/VariableName": tags.function(tags.variableName), | ||
"FunctionDefinition/VariableName": tags.function(tags.definition(tags.variableName)), | ||
"ClassDefinition/VariableName": tags.definition(tags.className), | ||
"CallExpression/VariableName": /*@__PURE__*/tags.function(tags.variableName), | ||
"FunctionDefinition/VariableName": /*@__PURE__*/tags.function(/*@__PURE__*/tags.definition(tags.variableName)), | ||
"ClassDefinition/VariableName": /*@__PURE__*/tags.definition(tags.className), | ||
PropertyName: tags.propertyName, | ||
"CallExpression/MemberExpression/ProperyName": tags.function(tags.propertyName), | ||
"CallExpression/MemberExpression/PropertyName": /*@__PURE__*/tags.function(tags.propertyName), | ||
Comment: tags.lineComment, | ||
Number: tags.number, | ||
String: tags.string, | ||
FormatString: tags.special(tags.string), | ||
FormatString: /*@__PURE__*/tags.special(tags.string), | ||
UpdateOp: tags.updateOperator, | ||
@@ -56,6 +70,8 @@ ArithOp: tags.arithmeticOperator, | ||
commentTokens: { line: "#" }, | ||
indentOnInput: /^\s*[\}\]\)]$/ | ||
indentOnInput: /^\s*([\}\]\)]|else:|elif |except |finally:)$/ | ||
} | ||
}); | ||
/// Python language support. | ||
/** | ||
Python language support. | ||
*/ | ||
function python() { | ||
@@ -62,0 +78,0 @@ return new LanguageSupport(pythonLanguage); |
{ | ||
"name": "@codemirror/lang-python", | ||
"version": "0.18.0", | ||
"version": "0.18.1", | ||
"description": "Python language support for the CodeMirror code editor", | ||
"scripts": { | ||
"test": "echo 'No tests'", | ||
"prepare": "tsc -p tsconfig.local.json && rollup -c" | ||
"test": "cm-runtests", | ||
"prepare": "cm-buildhelper src/python.ts" | ||
}, | ||
@@ -34,5 +34,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"rollup": "^2.35.1", | ||
"rollup-plugin-dts": "^2.0.1", | ||
"typescript": "^4.1.3" | ||
"@codemirror/buildhelper": "^0.1.0" | ||
}, | ||
@@ -39,0 +37,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
167
2
12693
8