Ejemplo n.º 1
0
 /**
  * Synchronize tern script paths with JSDT "Include Path"
  *
  * @param jsProject
  * @param ternProject
  */
 private void synchTernScriptPaths(IJavaScriptProject jsProject, IIDETernProject ternProject) {
   try {
     ternProject.removeExternalScriptPaths(JSDT_EXTERNAL_LABEL);
     IIncludePathEntry[] entries = jsProject.getRawIncludepath();
     for (int i = 0; i < entries.length; i++) {
       IIncludePathEntry entry = entries[i];
       switch (entry.getEntryKind()) {
         case IIncludePathEntry.CPE_LIBRARY:
           // TODO : manage JSDT library
           // JSDT Source file => Tern script path file.
           /*IFolder libFolder = ResourcesPlugin.getWorkspace().getRoot()
           		.getFolder(entry.getPath());
           try {
           	ternProject.addExternalScriptPath(libFolder,
           			ScriptPathsType.FOLDER, JSDT_EXTERNAL_LABEL);
           } catch (IOException e) {
           	Trace.trace(Trace.SEVERE,
           			"Error while adding external tern script path for project "
           					+ ternProject.getProject().getName(), e);
           }*/
           break;
         case IIncludePathEntry.CPE_SOURCE:
           if (entry.getPath().segmentCount() == 1) {
             // It's a project
             synchTernProjectScriptPaths(ternProject, entry);
           } else {
             // It's a folder
             // JSDT Source folder => Tern script path folder.
             IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath());
             try {
               ternProject.addExternalScriptPath(
                   folder, ScriptPathsType.FOLDER, JSDT_EXTERNAL_LABEL);
             } catch (IOException e) {
               Trace.trace(
                   Trace.SEVERE,
                   "Error while adding external tern script path for project "
                       + ternProject.getProject().getName(),
                   e);
             }
           }
           break;
         case IIncludePathEntry.CPE_PROJECT:
           // JS file?
           synchTernProjectScriptPaths(ternProject, entry);
           break;
       }
     }
   } catch (JavaScriptModelException e) {
     Trace.trace(
         Trace.SEVERE,
         "Error while getting JSDT ClassPath for project " + ternProject.getProject().getName(),
         e);
   }
 }
Ejemplo n.º 2
0
 /**
  * Synchronize tern project script paths with JSDT "Include Path"
  *
  * @param ternProject
  * @param entry
  */
 private void synchTernProjectScriptPaths(IIDETernProject ternProject, IIncludePathEntry entry) {
   // JSDT Project => Tern script path project.
   IProject project =
       ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment());
   try {
     ternProject.addExternalScriptPath(project, ScriptPathsType.PROJECT, JSDT_EXTERNAL_LABEL);
   } catch (IOException e) {
     Trace.trace(
         Trace.SEVERE,
         "Error while adding external tern script path for project "
             + ternProject.getProject().getName(),
         e);
   }
 }
Ejemplo n.º 3
0
  @Override
  public void commit(Object caller) throws IOException {
    removeCaller(caller);
    if (isDirty()) {
      try {
        // save tern project with updated tern modules
        ITernRepository repository = project.getRepository();
        // clear Plugin + JSON Type Definition
        project.clearPlugins();
        project.clearLibs();
        // Add Plugin + JSON Type Definition
        Collection<String> requiredDependencies = null;
        ITernModule dependencyModule = null;
        List<ITernModule> sortedModules = new ArrayList<ITernModule>();
        for (ITernModule module : this.getCheckedModules()) {
          TernModuleMetadata metadata = module.getMetadata();
          if (metadata != null) {
            // add required dependencies (ex : if ecma6 is checked,
            // ecma5 must
            // be added too).
            requiredDependencies = metadata.getRequiredDependencies(module.getVersion());
            for (String dependency : requiredDependencies) {
              dependencyModule = repository.getModule(dependency);
              if (dependencyModule != null && !sortedModules.contains(dependencyModule)) {
                sortedModules.add(dependencyModule);
              }
            }
          }
          if (module != null && !sortedModules.contains(module)) {
            sortedModules.add(module);
          }
        }
        TernModuleHelper.sort(sortedModules);
        for (ITernModule m : sortedModules) {
          TernModuleHelper.update(m, project);
        }
        project.save();

      } finally {
        clear();
      }
    }
  }
Ejemplo n.º 4
0
 public ITernConsole getConsole(IIDETernProject project) {
   if (project.isServerDisposed()) {
     return null;
   }
   if (!PlatformUI.isWorkbenchRunning()) {
     return null;
   }
   TernConsole console = TernConsole.getOrCreateConsole(project);
   TernConsoleHelper.ensureConsole(console);
   return console;
 }
Ejemplo n.º 5
0
 public void initialize() throws TernException {
   // Get local and global tern modules
   List<ITernModule> allModules = project.getAllModules();
   // Group by type
   workingCopyModules = TernModuleHelper.groupByType(allModules);
   // checked modules
   List<ITernModule> checkedModules =
       new WorkingCopyModuleList(
           this,
           TernCorePlugin.getTernRepositoryManager()
               .getCheckedModules(project, workingCopyModules));
   this.setCheckedModules(checkedModules);
 }
Ejemplo n.º 6
0
 /** Synchronize on the tern project load, tern script pats with JSDT "Include Path". */
 @Override
 public void handleEvent(IIDETernProject ternProject, LifecycleEventType eventType) {
   if (eventType != LifecycleEventType.onLoadAfter) {
     return;
   }
   // the given tern project is loading...
   IProject project = ternProject.getProject();
   if (JavaProject.hasJavaNature(project)) {
     // The project is a JSDT project.
     IJavaScriptProject jsProject = JavaScriptCore.create(project);
     // Synchronize tern script paths with JSDT "Include Path"
     synchTernScriptPaths(jsProject, ternProject);
   }
 }
  public JSTernCompletionCollector(
      List<ICompletionProposal> proposals,
      int startOffset,
      ITernFile ternFile,
      IIDETernProject ternProject) {
    this.proposals = proposals;
    this.ternFile = ternFile;
    this.ternProject = ternProject;

    IPreferencesService preferencesService = Platform.getPreferencesService();
    IScopeContext[] lookupOrder =
        new IScopeContext[] {
          new ProjectScope(ternProject.getProject()), new InstanceScope(), new DefaultScope()
        };

    generateAnonymousFunction =
        preferencesService.getBoolean(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.GENERATE_ANONYMOUS_FUNCTION_CONTENT_ASSIST,
            true,
            lookupOrder);

    int indentSize =
        preferencesService.getInt(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.INDENT_SIZE_CONTENT_ASSIST,
            TernUIPreferenceConstants.INDENT_SIZE_CONTENT_ASSIST_DEFAULT,
            lookupOrder);
    boolean indentWithTabs =
        preferencesService.getBoolean(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.INDENT_TABS_CONTENT_ASSIST,
            TernUIPreferenceConstants.INDENT_TABS_CONTENT_ASSIST_DEFAULT,
            lookupOrder);
    indentChars = getIndentChars(indentWithTabs, indentSize);

    expandFunction =
        preferencesService.getBoolean(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.EXPAND_FUNCTION_CONTENT_ASSIST,
            true,
            lookupOrder);
  }