From 028f450470c5bbe0dfcc4ca2f4d9477ab42b9d66 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Sun, 29 Sep 2024 09:41:23 -0300 Subject: [PATCH] wip --- .../ast/adapters/visitors/VisitorFactory.java | 22 ++++++++++++++++--- .../ast/refactoring/RefactoringInfo.java | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java index fab8b36c02..991594020e 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java @@ -20,12 +20,14 @@ import org.python.pydev.core.ISourceModule; import org.python.pydev.core.MisconfigurationException; import org.python.pydev.core.preferences.FileTypesPreferences; +import org.python.pydev.parser.PyParser; import org.python.pydev.parser.jython.SimpleNode; import org.python.pydev.parser.jython.ast.Module; import org.python.pydev.parser.jython.ast.VisitorIF; import org.python.pydev.parser.jython.ast.exprType; import org.python.pydev.shared_core.io.FileUtils; import org.python.pydev.shared_core.model.ISimpleNode; +import org.python.pydev.shared_core.parsing.BaseParser.ParseOutput; import org.python.pydev.shared_core.string.ICoreTextSelection; public final class VisitorFactory { @@ -76,6 +78,12 @@ public static T createVisitor(Class visitorClass, Simpl public static ModuleAdapter createModuleAdapter(PythonModuleManager pythonModuleManager, File file, IDocument doc, IPythonNature nature, IGrammarVersionProvider versionProvider) throws Throwable { + return createModuleAdapter(pythonModuleManager, file, doc, nature, versionProvider, false); + } + + public static ModuleAdapter createModuleAdapter(PythonModuleManager pythonModuleManager, File file, IDocument doc, + IPythonNature nature, IGrammarVersionProvider versionProvider, boolean acceptSyntaxErrors) + throws Throwable { if (file != null && file.exists()) { if (FileTypesPreferences.isCythonFile(file.getName())) { versionProvider = new IGrammarVersionProvider() { @@ -100,8 +108,10 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() IModule module = modulesManager.getModule(modName, nature, true, new BaseModuleRequest(false)); if (module instanceof ISourceModule) { SourceModule iSourceModule = (SourceModule) module; - if (iSourceModule.parseError != null) { - throw iSourceModule.parseError; + if (!acceptSyntaxErrors) { + if (iSourceModule.parseError != null) { + throw iSourceModule.parseError; + } } return new ModuleAdapter(pythonModuleManager, ((ISourceModule) module), nature, doc); } @@ -109,7 +119,13 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() } } } - ISimpleNode module = org.python.pydev.parser.PyParser.parseFull(doc, versionProvider).ast; + ParseOutput output = PyParser.parseFull(doc, versionProvider); + if (!acceptSyntaxErrors) { + if (output.error != null) { + throw output.error; + } + } + ISimpleNode module = output.ast; return new ModuleAdapter(pythonModuleManager, file, doc, (Module) module, nature); } diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/refactoring/RefactoringInfo.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/refactoring/RefactoringInfo.java index 56080df07b..4ae50fccbe 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/refactoring/RefactoringInfo.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/refactoring/RefactoringInfo.java @@ -125,7 +125,7 @@ private void initInfo(ICoreTextSelection selection) { try { this.moduleAdapter = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter( moduleManager, realFile, doc, nature, - this.versionProvider); + this.versionProvider, true); } catch (Throwable e) { throw new RuntimeException(e); }