}
return new DocumentBasedFormattingModel(root, file.getProject(), settings, file.getFileType(), file);
}
private static Block doCreateModel(PsiElement element) throws IOException, InterruptedException, NoMatchException {
final PsiFile file = element.getContainingFile();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null)
return null;
Module module = DeclarationPosition.getDeclModule(file);
CompilerLocation compiler = CompilerLocation.get(module);
if (compiler == null)
return null;
List<String> args = compiler.getCompileOptionsList(
"-m", "ParseTree",
virtualFile.getPath()
);
ProcessLauncher launcher = new ProcessLauncher(false, virtualFile.getInputStream(), args);
String stdOut = launcher.getStdOut();
if (stdOut.trim().isEmpty())
return null;
RangeFactory factory = new RangeFactory() {
public IRange parse(String str) {
LineColRange range = new LineColRange(str);
return new MyRange(range.getRange(file));
}
public IRange create(ILocation start, ILocation end) {
MyLocation from = (MyLocation) start;
MyLocation to = (MyLocation) end;
return MyLocation.create(from, to);
}
};
TreeParser parser = new TreeParser(new BufferedReader(new StringReader(stdOut)), factory);
ModuleTree moduleTree = parser.readTree(new MyRange(file.getTextRange()));
SortedMap<ILocation, Filler> ranges = new TreeMap<ILocation, Filler>();
String text = file.getText();
HaskellLexer lexer = new HaskellLexer();
lexer.start(text);
while (true) {
IElementType type = lexer.getTokenType();
if (type == null)