コード例 #1
0
  @Override
  public List computeCompletionProposals(
      CompletionProposalInvocationContext context, IProgressMonitor monitor) {
    final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();

    IFile file = DOMUtils.getFile(context.getDocument());
    if (file != null) {
      IProject project = file.getProject();
      if (IDETernProject.hasTernNature(project)) {

        IDocument document = context.getDocument();
        IResource resource = file;
        if (resource.getType() == IResource.FILE) {
          IFile scriptFile = (IFile) resource;

          try {

            IDETernProject ternProject = IDETernProject.getTernProject(project);

            TernCompletionsQuery query =
                new TernCompletionsQuery(
                    ternProject.getFileManager().getFileName(scriptFile),
                    context.getInvocationOffset());
            query.setTypes(true);
            query.setDocs(true);
            query.setUrls(true);
            query.setOrigins(true);
            query.setCaseInsensitive(true);
            query.setLineCharPositions(true);
            query.setExpandWordForward(false);

            int startOffset = context.getInvocationOffset();
            ternProject.request(
                query,
                scriptFile,
                document,
                startOffset,
                new JSTernCompletionCollector(proposals, startOffset));
            return proposals;

          } catch (Exception e) {
            Trace.trace(Trace.SEVERE, "Error while JSDT Tern completion.", e);
          }
        }
      }
    }
    return proposals;
  }
コード例 #2
0
 @Override
 public void synchronizeFile(TernDoc doc, ITernFile file) throws IOException {
   writeLock.lock();
   try {
     try {
       TernQuery query = doc.getQuery();
       if (query != null) {
         if (TernResourcesManager.isJSFile(file)) {
           addJSFile(doc, file);
           sendFiles(doc);
           return;
         } else if (TernResourcesManager.isHTMLFile(file)) {
           // This is HTML file case: never keep the file on the server
           String queryType = query.getType();
           if (TernCompletionsQuery.isQueryType(queryType)
               || TernDefinitionQuery.isQueryType(queryType)
               || query instanceof TernLintQuery) {
             addHTMLFile(doc, file);
             return;
           }
         }
       }
       TernFile tf = file.toTernServerFile(getProject());
       String oldText = sentFiles.get(tf.getName());
       if (tf.getText().equals(oldText) && !uploader.cancel(tf.getName())) {
         // no need to synchronize the file, already up-to-date
         return;
       }
       doc.addFile(tf);
     } finally {
       updateSentFiles(doc);
       // as this is
       // wait a bit for the sync to finish
       uploader.join(TIMEOUT);
     }
   } finally {
     writeLock.unlock();
   }
 }