Esempio n. 1
0
 public static void reveal(final HaskellEditor editor, final OutlineDef od) {
   Location srcLoc = od.getLocation();
   if (srcLoc != null) {
     IEditorInput fei = editor.getEditorInput();
     IDocument doc = editor.getDocumentProvider().getDocument(fei);
     try {
       int offset = srcLoc.getStartOffset(doc);
       int length = srcLoc.getEndOffset(doc) - offset;
       try {
         // editor.setHighlightRange( offset, length, true );
         editor.selectAndReveal(offset, length);
       } catch (IllegalArgumentException iaex) {
         editor.resetHighlightRange();
       }
     } catch (final BadLocationException badlox) {
       // ignore
     }
   }
 }
Esempio n. 2
0
 private CompositeChange createRenameChange(final IProgressMonitor pm) {
   CompositeChange result = null;
   if (info.getTargetEditor() instanceof HaskellEditor) {
     final HaskellEditor haskellEditor = (HaskellEditor) info.getTargetEditor();
     try {
       Location l = getLocation();
       if (l != null) {
         ThingAtPoint tap = getThingAtPoint(l);
         if (tap != null) {
           UsageQuery uq =
               ReferencesWorkspaceHandler.getUsageQuery(haskellEditor, getProject(), tap);
           uq.setScopeFlags(UsageQueryFlags.SCOPE_ALL);
           uq.run(pm);
           UsageSearchResult usr = (UsageSearchResult) uq.getSearchResult();
           if (usr.getResults().getSize() > 0) {
             CompositeChange cc =
                 ChangeCreator.getReferencesChange(usr.getResults(), tap.getName(), getNewName());
             return cc;
           } else {
             // nothing found: change locally
             List<Occurrence> occs =
                 haskellEditor
                     .getTokenScanner()
                     .getOccurrences(l.getStartOffset(haskellEditor.getDocument()));
             Location spanLocation =
                 haskellEditor.getOutlineSpan(
                     getLocation().getStartOffset(haskellEditor.getDocument()));
             if (spanLocation != null) {
               CompositeChange cc =
                   ChangeCreator.getLocalReferencesChange(
                       haskellEditor.findFile(), spanLocation, occs, tap.getName(), getNewName());
               return cc;
             }
           }
         }
       }
     } catch (Exception e) {
       HaskellUIPlugin.log(e);
     }
   }
   // TODO TtC replace by something not Cohatoe-based
   /*
   CohatoeServer server = CohatoeServer.getInstance();
   IRename fun = server.createFunction( IRename.class );
   if( fun != null ) {
     String newName = "I-AM-THE-NEW-NAME";
     int line = info.getLine();
     int column = info.getColumn();
     List<IReplaceEditDesc> descs
       = fun.performRename( info.getSourceFile(), line, column, newName );
     Map<IFile, List<IReplaceEditDesc>> map = mapByFile( descs );
     for( IFile file: map.keySet() ) {
       result = new TextFileChange( file.getName(), file );
       // a file change contains a tree of edits, first add the root of them
       MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
       result.setEdit( fileChangeRootEdit );
       // edit object for the text replacement in the file,
       // this is the only child
       List<IReplaceEditDesc> editDescs = map.get( file );
       for( IReplaceEditDesc editDesc: editDescs ) {
         ReplaceEdit edit = new ReplaceEdit( editDesc.getOffset(),
                                             editDesc.getLength(),
                                             editDesc.getReplacement() );
         fileChangeRootEdit.addChild( edit );
       }
     }
   }
   */
   return result;
 }