Example #1
0
  public HelpManager(PathConfig pcfg, PrintWriter stdout, PrintWriter stderr) {
    this.pcfg = pcfg;
    this.stdout = stdout;
    this.stderr = stderr;

    ISourceLocation binDir = pcfg.getBoot();
    coursesDir =
        URIUtil.correctLocation(
            binDir.getScheme(), binDir.getAuthority(), binDir.getPath() + "/courses");

    try {
      helpServer = new HelpServer(getPort(), this, coursesDir);
      indexSearcher = makeIndexSearcher();
    } catch (IOException e) {
      System.err.println("HelpManager: " + e.getMessage());
    }
  }
Example #2
0
 private CompletionResult completeLocation(String line, int locationStart) {
   int locationEnd = StringUtils.findRascalLocationEnd(line, locationStart);
   try {
     String locCandidate = line.substring(locationStart + 1, locationEnd + 1);
     if (!locCandidate.contains("://")) {
       return null;
     }
     ISourceLocation directory = VF.sourceLocation(new URI(locCandidate));
     String fileName = "";
     URIResolverRegistry reg = URIResolverRegistry.getInstance();
     if (!reg.isDirectory(directory)) {
       // split filename and directory
       String fullPath = directory.getPath();
       int lastSeparator = fullPath.lastIndexOf('/');
       fileName = fullPath.substring(lastSeparator + 1);
       fullPath = fullPath.substring(0, lastSeparator);
       directory = VF.sourceLocation(directory.getScheme(), directory.getAuthority(), fullPath);
       if (!reg.isDirectory(directory)) {
         return null;
       }
     }
     String[] filesInPath = reg.listEntries(directory);
     URI directoryURI = directory.getURI();
     Set<String> result = new TreeSet<>(); // sort it up
     for (String currentFile : filesInPath) {
       if (currentFile.startsWith(fileName)) {
         URI currentDir = URIUtil.getChildURI(directoryURI, currentFile);
         boolean isDirectory = reg.isDirectory(VF.sourceLocation(currentDir));
         result.add(currentDir.toString() + (isDirectory ? "/" : "|"));
       }
     }
     if (result.size() > 0) {
       return new CompletionResult(locationStart + 1, result);
     }
     return null;
   } catch (URISyntaxException | IOException e) {
     return null;
   }
 }