示例#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());
    }
  }
示例#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;
   }
 }
示例#3
0
  public ISourceLocation resolveSourceLocation(ISourceLocation loc) {
    String scheme = loc.getScheme();
    int pos;

    ICallableValue resolver = sourceResolvers.get(scheme);
    if (resolver == null) {
      for (char sep : new char[] {'+', ':'}) {
        pos = scheme.indexOf(sep);
        if (pos != -1) {
          scheme = scheme.substring(0, pos);
        }
      }

      resolver = sourceResolvers.get(scheme);
      if (resolver == null) {
        return loc;
      }
    }

    Type[] argTypes = new Type[] {TypeFactory.getInstance().sourceLocationType()};
    IValue[] argValues = new IValue[] {loc};

    return (ISourceLocation) resolver.call(argTypes, argValues, null).getValue();
  }