| 48 | import static java.util.Arrays.copyOfRange; |
| 49 | |
| 50 | class PdeAdapter { |
| 51 | File rootPath; |
| 52 | LanguageClient client; |
| 53 | JavaMode javaMode; |
| 54 | File pdeFile; |
| 55 | Sketch sketch; |
| 56 | CompletionGenerator completionGenerator; |
| 57 | PreprocService preprocService; |
| 58 | ErrorChecker errorChecker; |
| 59 | CompletableFuture<PreprocSketch> cps; |
| 60 | CompletionGenerator suggestionGenerator; |
| 61 | Set<URI> prevDiagnosticReportUris = new HashSet<>(); |
| 62 | PreprocSketch ps; |
| 63 | |
| 64 | |
| 65 | PdeAdapter(File rootPath, LanguageClient client) { |
| 66 | this.rootPath = rootPath; |
| 67 | this.client = client; |
| 68 | |
| 69 | File location = Platform.getContentFile("modes/java"); |
| 70 | ModeContribution mc = |
| 71 | ModeContribution.load(null, location, JavaMode.class.getName()); |
| 72 | if (mc == null) { |
| 73 | // Shouldn't be possible but IntelliJ is complaining about it, |
| 74 | // and we may run into path issues when running externally [fry 221126] |
| 75 | throw new RuntimeException("Could not load Java Mode from " + location); |
| 76 | } |
| 77 | javaMode = (JavaMode) mc.getMode(); |
| 78 | |
| 79 | pdeFile = new File(rootPath, rootPath.getName() + ".pde"); |
| 80 | sketch = new Sketch(pdeFile.toString(), javaMode); |
| 81 | completionGenerator = new CompletionGenerator(javaMode); |
| 82 | preprocService = new PreprocService(javaMode, sketch); |
| 83 | errorChecker = new ErrorChecker(this::updateProblems, preprocService); |
| 84 | cps = CompletableFutures.computeAsync(_x -> { |
| 85 | throw new RuntimeException("unreachable"); |
| 86 | }); |
| 87 | suggestionGenerator = new CompletionGenerator(javaMode); |
| 88 | |
| 89 | notifySketchChanged(); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | static Optional<File> uriToPath(URI uri) { |
| 94 | try { |
| 95 | return Optional.of(new File(uri)); |
| 96 | } catch (Exception e) { |
| 97 | return Optional.empty(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static URI pathToUri(File path) { |
| 103 | return path.toURI(); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | static Offset toLineCol(String s, int offset) { |
nothing calls this directly
no outgoing calls
no test coverage detected