import{p as h}from"./vendor-lezer-python-DDPChHKC.js";import{L as S,s as I,c as v,d as k,f as C,h as m,k as $}from"./cm-language-CDsY7zq0.js";import{a as A,I as F}from"./vendor-lezer-common-tVQBIsvN.js";import{i as w,c as N,s}from"./cm-autocomplete-t9rzw_D0.js";import"./vendor-lezer-lr-eZ5kYecM.js";import"./vendor-lezer-highlight-DuEf3ZFH.js";import"./cm-state-X9WpHEQO.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./cm-view-CiSFjroV.js";import"./vendor-style-mod-Bs6eFhZE.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";const c=new A,E=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function p(e){return(r,t,n)=>{if(n)return!1;let o=r.node.getChild("VariableName");return o&&t(o,e),!0}}const B={FunctionDefinition:p("function"),ClassDefinition:p("class"),ForStatement(e,r,t){if(t){for(let n=e.node.firstChild;n;n=n.nextSibling)if(n.name=="VariableName")r(n,"variable");else if(n.name=="in")break}},ImportStatement(e,r){var t,n;let{node:o}=e,a=((t=o.firstChild)===null||t===void 0?void 0:t.name)=="from";for(let i=o.getChild("import");i;i=i.nextSibling)i.name=="VariableName"&&((n=i.nextSibling)===null||n===void 0?void 0:n.name)!="as"&&r(i,a?"variable":"namespace")},AssignStatement(e,r){for(let t=e.node.firstChild;t;t=t.nextSibling)if(t.name=="VariableName")r(t,"variable");else if(t.name==":"||t.name=="AssignOp")break},ParamList(e,r){for(let t=null,n=e.node.firstChild;n;n=n.nextSibling)n.name=="VariableName"&&(!t||!/\*|AssignOp/.test(t.name))&&r(n,"variable"),t=n},CapturePattern:p("variable"),AsPattern:p("variable"),__proto__:null};function y(e,r){let t=c.get(r);if(t)return t;let n=[],o=!0;function a(i,l){let _=e.sliceString(i.from,i.to);n.push({label:_,type:l})}return r.cursor(F.IncludeAnonymous).iterate(i=>{if(i.name){let l=B[i.name];if(l&&l(i,a,o)||!o&&E.has(i.name))return!1;o=!1}else if(i.to-i.from>8192){for(let l of y(e,i.node))n.push(l);return!1}}),c.set(r,n),n}const b=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,g=["String","FormatString","Comment","PropertyName"];function x(e){let r=I(e.state).resolveInner(e.pos,-1);if(g.indexOf(r.name)>-1)return null;let t=r.name=="VariableName"||r.to-r.from<20&&b.test(e.state.sliceDoc(r.from,r.to));if(!t&&!e.explicit)return null;let n=[];for(let o=r;o;o=o.parent)E.has(o.name)&&(n=n.concat(y(e.state.doc,o)));return{options:n,from:t?r.from:e.pos,validFor:b}}const D=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(e=>({label:e,type:"constant"})).concat(["ArithmeticError","AssertionError","AttributeError","BaseException","BlockingIOError","BrokenPipeError","BufferError","BytesWarning","ChildProcessError","ConnectionAbortedError","ConnectionError","ConnectionRefusedError","ConnectionResetError","DeprecationWarning","EOFError","Ellipsis","EncodingWarning","EnvironmentError","Exception","FileExistsError","FileNotFoundError","FloatingPointError","FutureWarning","GeneratorExit","IOError","ImportError","ImportWarning","IndentationError","IndexError","InterruptedError","IsADirectoryError","KeyError","KeyboardInterrupt","LookupError","MemoryError","ModuleNotFoundError","NameError","NotADirectoryError","NotImplemented","NotImplementedError","OSError","OverflowError","PendingDeprecationWarning","PermissionError","ProcessLookupError","RecursionError","ReferenceError","ResourceWarning","RuntimeError","RuntimeWarning","StopAsyncIteration","StopIteration","SyntaxError","SyntaxWarning","SystemError","SystemExit","TabError","TimeoutError","TypeError","UnboundLocalError","UnicodeDecodeError","UnicodeEncodeError","UnicodeError","UnicodeTranslateError","UnicodeWarning","UserWarning","ValueError","Warning","ZeroDivisionError"].map(e=>({label:e,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(e=>({label:e,type:"class"}))).concat(["abs","aiter","all","anext","any","ascii","bin","breakpoint","callable","chr","compile","delattr","dict","dir","divmod","enumerate","eval","exec","exit","filter","format","getattr","globals","hasattr","hash","help","hex","id","input","isinstance","issubclass","iter","len","license","locals","max","min","next","oct","open","ord","pow","print","property","quit","repr","reversed","round","setattr","slice","sorted","sum","vars","zip"].map(e=>({label:e,type:"function"}))),P=[s("def ${name}(${params}):\n	${}",{label:"def",detail:"function",type:"keyword"}),s("for ${name} in ${collection}:\n	${}",{label:"for",detail:"loop",type:"keyword"}),s("while ${}:\n	${}",{label:"while",detail:"loop",type:"keyword"}),s("try:\n	${}\nexcept ${error}:\n	${}",{label:"try",detail:"/ except block",type:"keyword"}),s(`if \${}:
	
`,{label:"if",detail:"block",type:"keyword"}),s("if ${}:\n	${}\nelse:\n	${}",{label:"if",detail:"/ else block",type:"keyword"}),s("class ${name}:\n	def __init__(self, ${params}):\n			${}",{label:"class",detail:"definition",type:"keyword"}),s("import ${module}",{label:"import",detail:"statement",type:"keyword"}),s("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],W=w(g,N(D.concat(P)));function d(e){let{node:r,pos:t}=e,n=e.lineIndent(t,-1),o=null;for(;;){let a=r.childBefore(t);if(a)if(a.name=="Comment")t=a.from;else if(a.name=="Body"||a.name=="MatchBody")e.baseIndentFor(a)+e.unit<=n&&(o=a),r=a;else if(a.name=="MatchClause")r=a;else if(a.type.is("Statement"))r=a;else break;else break}return o}function f(e,r){let t=e.baseIndentFor(r),n=e.lineAt(e.pos,-1),o=n.from+n.text.length;return/^\s*($|#)/.test(n.text)&&e.node.to<o+100&&!/\S/.test(e.state.sliceDoc(o,e.node.to))&&e.lineIndent(e.pos,-1)<=t||/^\s*(else:|elif |except |finally:|case\s+[^=:]+:)/.test(e.textAfter)&&e.lineIndent(e.pos,-1)>t?null:t+e.unit}const u=S.define({name:"python",parser:h.configure({props:[k.add({Body:e=>{var r;let t=/^\s*(#|$)/.test(e.textAfter)&&d(e)||e.node;return(r=f(e,t))!==null&&r!==void 0?r:e.continue()},MatchBody:e=>{var r;let t=d(e);return(r=f(e,t||e.node))!==null&&r!==void 0?r:e.continue()},IfStatement:e=>/^\s*(else:|elif )/.test(e.textAfter)?e.baseIndent:e.continue(),"ForStatement WhileStatement":e=>/^\s*else:/.test(e.textAfter)?e.baseIndent:e.continue(),TryStatement:e=>/^\s*(except[ :]|finally:|else:)/.test(e.textAfter)?e.baseIndent:e.continue(),MatchStatement:e=>/^\s*case /.test(e.textAfter)?e.baseIndent+e.unit:e.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":m({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":m({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":m({closing:"]"}),MemberExpression:e=>e.baseIndent+e.unit,"String FormatString":()=>null,Script:e=>{var r;let t=d(e);return(r=t&&f(e,t))!==null&&r!==void 0?r:e.continue()}}),C.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":$,Body:(e,r)=>({from:e.from+1,to:e.to-(e.to==r.doc.length?0:1)}),"String FormatString":(e,r)=>({from:r.doc.lineAt(e.from).to,to:e.to})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""'],stringPrefixes:["f","fr","rf","r","u","b","br","rb","F","FR","RF","R","U","B","BR","RB"]},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:|case\s+[^:]*:?)$/}});function Z(){return new v(u,[u.data.of({autocomplete:x}),u.data.of({autocomplete:W})])}export{W as globalCompletion,x as localCompletionSource,Z as python,u as pythonLanguage};
