Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 29, 2024
1 parent 891a22a commit 028f450
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -76,6 +78,12 @@ public static <T extends VisitorIF> T createVisitor(Class<T> 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() {
Expand All @@ -100,16 +108,24 @@ 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);
}
}
}
}
}
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 028f450

Please sign in to comment.