use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method execution_mapUri.
@Nullable
public String execution_mapUri(@NotNull final String _id, @Nullable final String _filePath, @Nullable final String _uri) {
// be generated. Similarly, if neither field is provided, then an error of type INVALID_PARAMETER will be generated.
if ((_filePath == null && _uri == null) || (_filePath != null && _uri != null)) {
LOG.error("One of _filePath and _uri must be non-null.");
return null;
}
final String filePath = _filePath != null ? FileUtil.toSystemDependentName(_filePath) : null;
final Ref<String> resultRef = new Ref<>();
final AnalysisServer server = myServer;
if (server == null)
return null;
final CountDownLatch latch = new CountDownLatch(1);
server.execution_mapUri(_id, filePath, _uri, new MapUriConsumer() {
@Override
public void computedFileOrUri(final String file, final String uri) {
if (uri != null) {
resultRef.set(uri);
} else {
resultRef.set(file);
}
latch.countDown();
}
@Override
public void onError(final RequestError error) {
LOG.warn("execution_mapUri(" + _id + ", " + filePath + ", " + _uri + ") returned error " + error.getCode() + ": " + error.getMessage());
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, EXECUTION_MAP_URI_TIMEOUT);
if (latch.getCount() > 0) {
LOG.info("execution_mapUri() took too long for contextID " + _id + " and file or uri " + (filePath != null ? filePath : _uri));
return null;
}
if (_uri != null && !resultRef.isNull()) {
return FileUtil.toSystemIndependentName(resultRef.get());
}
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method edit_getRefactoring.
public boolean edit_getRefactoring(String kind, VirtualFile file, int _offset, int _length, boolean validateOnly, RefactoringOptions options, GetRefactoringConsumer consumer) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final AnalysisServer server = myServer;
if (server == null)
return false;
final int offset = getOriginalOffset(file, _offset);
final int length = getOriginalOffset(file, _offset + _length) - offset;
server.edit_getRefactoring(kind, filePath, offset, length, validateOnly, options, consumer);
return true;
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method completion_getSuggestions.
@Nullable
public String completion_getSuggestions(@NotNull final VirtualFile file, final int _offset) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final Ref<String> resultRef = new Ref<>();
final AnalysisServer server = myServer;
if (server == null) {
return null;
}
final CountDownLatch latch = new CountDownLatch(1);
final int offset = getOriginalOffset(file, _offset);
server.completion_getSuggestions(filePath, offset, new GetSuggestionsConsumer() {
@Override
public void computedCompletionId(@NotNull final String completionId) {
resultRef.set(completionId);
latch.countDown();
}
@Override
public void onError(@NotNull final RequestError error) {
// Not a problem. Happens if a file is outside of the project, or server is just not ready yet.
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, GET_SUGGESTIONS_TIMEOUT);
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method edit_format.
@Nullable
public FormatResult edit_format(@NotNull final VirtualFile file, final int _selectionOffset, final int _selectionLength, final int lineLength) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final Ref<FormatResult> resultRef = new Ref<>();
final AnalysisServer server = myServer;
if (server == null)
return null;
final CountDownLatch latch = new CountDownLatch(1);
final int selectionOffset = getOriginalOffset(file, _selectionOffset);
final int selectionLength = getOriginalOffset(file, _selectionOffset + _selectionLength) - selectionOffset;
server.edit_format(filePath, selectionOffset, selectionLength, lineLength, new FormatConsumer() {
@Override
public void computedFormat(final List<SourceEdit> edits, final int selectionOffset, final int selectionLength) {
resultRef.set(new FormatResult(edits, selectionOffset, selectionLength));
latch.countDown();
}
@Override
public void onError(final RequestError error) {
if (RequestErrorCode.FORMAT_WITH_ERRORS.equals(error.getCode()) || RequestErrorCode.FORMAT_INVALID_FILE.equals(error.getCode())) {
LOG.info(getShortErrorMessage("edit_format()", filePath, error));
} else {
logError("edit_format()", filePath, error);
}
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, EDIT_FORMAT_TIMEOUT);
if (latch.getCount() > 0) {
LOG.info("edit_format() took too long for file " + filePath);
}
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method search_getTypeHierarchy.
@NotNull
public List<TypeHierarchyItem> search_getTypeHierarchy(@NotNull final VirtualFile file, final int _offset, final boolean superOnly) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final List<TypeHierarchyItem> results = Lists.newArrayList();
final AnalysisServer server = myServer;
if (server == null) {
return results;
}
final CountDownLatch latch = new CountDownLatch(1);
final int offset = getOriginalOffset(file, _offset);
server.search_getTypeHierarchy(filePath, offset, superOnly, new GetTypeHierarchyConsumer() {
@Override
public void computedHierarchy(List<TypeHierarchyItem> hierarchyItems) {
results.addAll(hierarchyItems);
latch.countDown();
}
@Override
public void onError(RequestError error) {
logError("search_getTypeHierarchy()", filePath, error);
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, GET_TYPE_HIERARCHY_TIMEOUT);
return results;
}
Aggregations