private void UpdateFromImport(PythonAst curAst, FromImportStatement fromImport) { NameExpression[] names = new NameExpression[fromImport.Names.Count + 1]; NameExpression[] asNames = fromImport.AsNames == null ? null : new NameExpression[fromImport.AsNames.Count + 1]; NameExpression newName = new NameExpression(Name); for (int i = 0; i < fromImport.Names.Count; i++) { names[i] = fromImport.Names[i]; } names[fromImport.Names.Count] = newName; if (asNames != null) { for (int i = 0; i < fromImport.AsNames.Count; i++) { asNames[i] = fromImport.AsNames[i]; } } var newImport = new FromImportStatement((ModuleName)fromImport.Root, names, asNames, fromImport.IsFromFuture, fromImport.ForceAbsolute); curAst.CopyAttributes(fromImport, newImport); var newCode = newImport.ToCodeString(curAst); var span = fromImport.GetSpan(curAst); int leadingWhiteSpaceLength = (fromImport.GetLeadingWhiteSpace(curAst) ?? "").Length; using (var edit = _buffer.CreateEdit()) { edit.Delete(span.Start.Index - leadingWhiteSpaceLength, span.Length + leadingWhiteSpaceLength); edit.Insert(span.Start.Index, newCode); edit.Apply(); } }
public override string ToCodeString(PythonAst ast) { return(_fromImport.ToCodeString(ast)); }