public AbstractEditorOperation2(String operationName, ITextEditor editor) { super(operationName); this.editor = assertNotNull(editor); this.window = editor.getSite().getWorkbenchWindow(); this.editorInput = editor.getEditorInput(); Path inputPath = EditorUtils.getFilePathFromEditorInput(editorInput); this.inputLoc = Location.createValidOrNull(inputPath); this.doc = assertNotNull(editor.getDocumentProvider().getDocument(editor.getEditorInput())); }
@Override protected Indexable<ICompletionProposal> computeProposals( SourceOperationContext context, int offset, TimeoutProgressMonitor pm) throws CoreException, CommonException, OperationCancellation, OperationSoftFailure { IEditorPart editor = context.getEditor_nonNull(); Location fileLoc = context.getEditorInputLocation(); IDocument document = context.getDocument(); String prefix = lastWord(document, offset); GoUIPlugin.prepareGocodeManager_inUI(); IPath gocodePath = GocodeServerManager.getGocodePath(); if (gocodePath == null) { throw LangCore.createCoreException("Error: gocode path not provided.", null); } IProject project = getProjectFor(editor); GoEnvironment goEnvironment = GoProjectEnvironment.getGoEnvironment(project); // TODO: we should run this operation outside the UI thread. GocodeCompletionOperation client = new GocodeCompletionOperation( getEngineToolRunner(pm), goEnvironment, gocodePath.toOSString()); ExternalProcessResult processResult = client.execute(fileLoc.toPathString(), document.get(), offset); String stdout = processResult.getStdOutBytes().toString(StringUtil.UTF8); List<String> completions = new ArrayList2<>(GocodeCompletionOperation.LINE_SPLITTER.split(stdout)); ArrayList2<ICompletionProposal> results = new ArrayList2<>(); for (String completionEntry : completions) { handleResult(offset, /*codeContext,*/ results, prefix, completionEntry); } return results; }