Search in sources :

Example 1 with LanguageDescriptionDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO in project che by eclipse.

the class LanguageServerFileTypeRegister method start.

@Override
public void start(final Callback<WsAgentComponent, Exception> callback) {
    Promise<List<LanguageDescriptionDTO>> registeredLanguages = serverLanguageRegistry.getSupportedLanguages();
    registeredLanguages.then(new Operation<List<LanguageDescriptionDTO>>() {

        @Override
        public void apply(List<LanguageDescriptionDTO> langs) throws OperationException {
            if (!langs.isEmpty()) {
                JsArrayString contentTypes = JsArrayString.createArray().cast();
                for (LanguageDescriptionDTO lang : langs) {
                    String primaryExtension = lang.getFileExtensions().get(0);
                    for (String ext : lang.getFileExtensions()) {
                        final FileType fileType = new FileType(resources.file(), ext);
                        fileTypeRegistry.registerFileType(fileType);
                        editorRegistry.registerDefaultEditor(fileType, editorProvider);
                        ext2langId.put(ext, lang.getLanguageId());
                    }
                    List<String> mimeTypes = lang.getMimeTypes();
                    if (mimeTypes.isEmpty()) {
                        mimeTypes = newArrayList("text/x-" + lang.getLanguageId());
                    }
                    for (String contentTypeId : mimeTypes) {
                        contentTypes.push(contentTypeId);
                        OrionContentTypeOverlay contentType = OrionContentTypeOverlay.create();
                        contentType.setId(contentTypeId);
                        contentType.setName(lang.getLanguageId());
                        contentType.setExtension(primaryExtension);
                        contentType.setExtends("text/plain");
                        // highlighting
                        OrionHighlightingConfigurationOverlay config = OrionHighlightingConfigurationOverlay.create();
                        config.setId(lang.getLanguageId() + ".highlighting");
                        config.setContentTypes(contentTypeId);
                        config.setPatterns(lang.getHighlightingConfiguration());
                        Logger logger = Logger.getLogger(LanguageServerFileTypeRegister.class.getName());
                        contentTypeRegistrant.registerFileType(contentType, config);
                    }
                }
                orionHoverRegistrant.registerHover(contentTypes, hoverProvider);
                orionOccurrencesRegistrant.registerOccurrencesHandler(contentTypes, occurrencesProvider);
            }
            callback.onSuccess(LanguageServerFileTypeRegister.this);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            callback.onFailure(new Exception(arg.getMessage(), arg.getCause()));
        }
    });
}
Also used : OrionHighlightingConfigurationOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionHighlightingConfigurationOverlay) LanguageDescriptionDTO(org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO) OrionContentTypeOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionContentTypeOverlay) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Logger(java.util.logging.Logger) OperationException(org.eclipse.che.api.promises.client.OperationException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FileType(org.eclipse.che.ide.api.filetypes.FileType) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with LanguageDescriptionDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO in project che by eclipse.

the class DtoConverter method asDto.

public static LanguageDescriptionDTO asDto(LanguageDescription languageDescription) {
    LanguageDescriptionDTO languageDescriptionDTO = newDto(LanguageDescriptionDTO.class);
    languageDescriptionDTO.setFileExtensions(languageDescription.getFileExtensions());
    languageDescriptionDTO.setHighlightingConfiguration(languageDescription.getHighlightingConfiguration());
    languageDescriptionDTO.setLanguageId(languageDescription.getLanguageId());
    languageDescriptionDTO.setMimeTypes(languageDescription.getMimeTypes());
    return languageDescriptionDTO;
}
Also used : LanguageDescriptionDTO(org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO)

Aggregations

LanguageDescriptionDTO (org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 List (java.util.List)1 Logger (java.util.logging.Logger)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 FileType (org.eclipse.che.ide.api.filetypes.FileType)1 OrionContentTypeOverlay (org.eclipse.che.ide.editor.orion.client.jso.OrionContentTypeOverlay)1 OrionHighlightingConfigurationOverlay (org.eclipse.che.ide.editor.orion.client.jso.OrionHighlightingConfigurationOverlay)1