<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.lsp4e.languageServer">
      <server
            class="org.springframework.tooling.boot.ls.DelegatingStreamConnectionProvider"
            id="org.eclipse.languageserver.languages.springboot"
            clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl"
            label="Spring Boot Language Server">
      </server>

      <contentTypeMapping
            contentType="org.eclipse.jdt.core.javaSource"
            id="org.eclipse.languageserver.languages.springboot">
      </contentTypeMapping>

      <contentTypeMapping
            contentType="org.springframework.boot.ide.properties.application.properties"
            id="org.eclipse.languageserver.languages.springboot"
            languageId="spring-boot-properties">
      </contentTypeMapping>

      <contentTypeMapping
            contentType="org.springframework.boot.ide.properties.application.yml"
            id="org.eclipse.languageserver.languages.springboot"
            languageId="spring-boot-properties-yaml">
      </contentTypeMapping>

      <contentTypeMapping
            contentType="org.springframework.boot.ide.xmlconfig"
            id="org.eclipse.languageserver.languages.springboot">
      </contentTypeMapping>

   </extension>

   <extension
         point="org.eclipse.core.contenttype.contentTypes">

<!--
      WARNING! 
      
      TLDR; Always put 
         base-type="org.eclipse.core.runtime.text" 
      in *every* content type definiton.
      
      Longer explanation:
      
      Do not use  
      base-type="org.eclipse.jdt.core.javaProperties"
      this causes reconciling of *any* properties file
      as if it was a boot properties file.
      
      Similarly
      base-type="org.eclipse.core.runtime.xml" 
      causes reconciling of *any* XML file
      as if it was a Spring xml config file.
      
      Also to avoid some suspected bug/weirdness in Lsp4e
      which I do not really understand, a base-type must allways 
      be added. Therefore the only possible choice 
      that makes everything work is
      "org.eclipse.core.runtime.text".
      
      See: https://github.com/spring-projects/sts4/issues/320
  -->
      <content-type
            base-type="org.eclipse.core.runtime.text"
            default-charset="ISO-8859-1"
            file-names="application.properties,application-dev.properties"
            file-patterns="application-*.properties"
            id="org.springframework.boot.ide.properties.application.properties"
            name="Spring Properties File"
            priority="high">
      </content-type>

      <content-type
            base-type="org.eclipse.core.runtime.text"
            default-charset="UTF-8"
            file-names="application.yml,bootstrap.yml,application-dev.yml,application.yaml,bootstrap.yaml,application-dev.yaml"
            file-patterns="application-*.yml,application-*.yaml"
            id="org.springframework.boot.ide.properties.application.yml"
            name="Spring Yaml Properties File"
            priority="high">
      </content-type>

      <content-type
            base-type="org.eclipse.core.runtime.xml"
            default-charset="UTF-8"
            id="org.springframework.boot.ide.xmlconfig"
            name="Spring XML Config File"
            priority="normal">
            <describer class="org.springframework.tooling.boot.ls.xml.XMLRootElementContentDescriber2">
                  <parameter name="element" value="beans"/>
            </describer>
      </content-type>

      <file-association
            content-type="org.springframework.boot.ide.properties.application.properties"
            file-names="application.properties,application-dev.properties"
            file-patterns="application-*.properties">
      </file-association>

      <file-association
            content-type="org.springframework.boot.ide.properties.application.yml"
            file-names="application.yml,bootstrap.yml,application-dev.yml,application.yaml,bootstrap.yaml,application-dev.yaml"
            file-patterns="application-*.yml,application-*.yaml">
      </file-association>

   </extension>
   
   <extension
         id="springbootjava-completion-computer"
         name="Spring Proposals (based on Spring Boot LS)"
         point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
      <javaCompletionProposalComputer
            activate="true"
            categoryId="org.springframework.tooling.boot.ls.springbootjava-completion-computer"
            class="org.springframework.tooling.boot.ls.jdt.SpringBootJavaCompletionProposalComputer"
            needsSortingAfterFiltering="false">
      </javaCompletionProposalComputer>
   </extension>
   
   <extension
         id="springbootjava-hover-provider"
         point="org.eclipse.jdt.ui.javaEditorTextHovers">
      <hover
            activate="true"
            class="org.springframework.tooling.boot.ls.jdt.SpringBootJavaHoverProvider"
            id="org.springframework.boot.ide.java.servers.hoverprovider">
      </hover>
   </extension>
   
   <extension
         point="org.eclipse.core.filebuffers.documentSetup">
      <participant
            class="org.eclipse.lsp4e.ConnectDocumentToLanguageServerSetupParticipant"
            contentTypeId="org.eclipse.jdt.core.javaSource">
      </participant>
   </extension>

   <extension
         point="org.eclipse.ui.preferencePages">
      <page
            category="org.springframework.tooling.boot.java.ls.preferences"
            class="org.springframework.tooling.boot.ls.prefs.RemoteAppsPrefsPage"
            id="org.springframework.tooling.boot.ls.prefs.RemoteAppsPrefsPage"
            name="Remote Boot Apps">
      </page>
      <page
            category="org.springframework.tooling.boot.ls.preferences"
            class="org.springframework.tooling.boot.ls.BootJavaPreferencesPage"
            id="org.springframework.tooling.boot.java.ls.preferences"
            name="Spring Boot Java">
      </page>
      <page
            category="org.springframework.tooling.boot.ls.preferences"
            class="org.springframework.tooling.boot.ls.XmlConfigPreferencePage"
            id="org.springframework.tooling.boot.xml.ls.preferences"
            name="Spring XML Config">
      </page>
      <page
            category="org.springframework.tooling.ls.eclipse.commons.console.preferences"
            class="org.springframework.tooling.boot.ls.SpringBootLanguageServerPreferencePage"
            id="org.springframework.tooling.boot.ls.preferences"
            name="Spring Boot Language Server">
      </page>
   </extension>
   
   <extension
         point="org.eclipse.core.runtime.preferences">
      <initializer
            class="org.springframework.tooling.boot.ls.PrefsInitializer">
      </initializer>
   </extension>
   
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="org.springframework.tooling.boot.ls.commands.ToggleComment"
            commandId="org.springframework.tooling.boot.ls.ToggleComment">
             <activeWhen>
              <with variable="activeEditorId">
                <or>
                  <equals value="SpringBootPropertyEditor"/>
                  <equals value="SpringBootYMLPropertyEditor"/>
                </or>
              </with>
            </activeWhen>
      </handler>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
      <!-- !!! category for command is required or keybindings don't work !!! -->
      <category
            description="Spring Language Server Commands"
            id="org.springframework.ide.eclipse.commands"
            name="Spring Generic Text Editor">
      </category>
      <command
            id="org.springframework.tooling.boot.ls.ToggleComment"
            categoryId="org.springframework.ide.eclipse.commands"
            name="Toggle Comment">
      </command>
   </extension>

	<extension
	     point="org.eclipse.ui.bindings">
      <!--  win32:  M1=CTRL,    M2=SHIFT, M3=ALT, M4=-
            carbon: M1=COMMAND, M2=SHIFT, M3=ALT, M4=CTRL -->
      <key
            sequence="M1+M2+C"
            contextId="org.eclipse.ui.textEditorScope"
            commandId="org.springframework.tooling.boot.ls.ToggleComment"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
      <key
            sequence="M1+/"
            contextId="org.eclipse.ui.textEditorScope"
            commandId="org.springframework.tooling.boot.ls.ToggleComment"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
	</extension>

   <!-- Note: locationURI below adds this to 'edit' menu. Not a great place. Decided instead to just 
        disable this. If we want to show this in a menu somewhere we should decide where and figure out how/if we
        can make it apear there. -->
<!--   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:edit?after=selectAll">
        <command
              commandId="org.springframework.tooling.boot.ls.ToggleComment"
              label="Toggle Comment Spring"
              style="push">
            <visibleWhen
                  checkEnabled="false">
               <with
                     variable="activePartId">
                  <equals
                        value="SpringBootPropertyEditor">
                  </equals>
               </with>
            </visibleWhen>
        </command>
      </menuContribution>
   </extension> -->   
   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor"
            contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
            icon="icons/spring_obj.gif"
            id="SpringBootPropertyEditor"
            name="Generic Editor - Spring Properties"
            symbolicFontName="org.eclipse.jdt.ui.PropertiesFileEditor.textfont">
            <contentTypeBinding
               contentTypeId="org.springframework.boot.ide.properties.application.properties"
            /> 
      </editor>
   </extension>
   
   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="org.springframework.tooling.ls.eclipse.commons.YamlGenericEditor"
            contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
            icon="icons/spring_yml.png"
            id="SpringBootYMLPropertyEditor"
            name="Generic Editor - Spring YAML Properties"
            symbolicFontName="org.eclipse.jdt.ui.PropertiesFileEditor.textfont">
            <contentTypeBinding
               contentTypeId="org.springframework.boot.ide.properties.application.yml"
            /> 
      </editor>
   </extension>

   <extension
         point="org.eclipse.ui.genericeditor.presentationReconcilers">
      <presentationReconciler
            class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
            contentType="org.springframework.boot.ide.properties.application.properties">
      </presentationReconciler>
   </extension>

   <extension
         point="org.eclipse.ui.genericeditor.presentationReconcilers">
      <presentationReconciler
            class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
            contentType="org.springframework.boot.ide.properties.application.yml">
      </presentationReconciler>
   </extension>

   <extension
         point="org.eclipse.tm4e.registry.grammars">
      <grammar
      		scopeName="source.yaml"
            path="./syntaxes/YAML.tmLanguage" >
      </grammar>      
      <scopeNameContentTypeBinding
            contentTypeId="org.springframework.boot.ide.properties.application.yml"
            scopeName="source.yaml">
      </scopeNameContentTypeBinding>
   </extension>

   <extension
         point="org.eclipse.tm4e.registry.grammars">
      <grammar
      		scopeName="source.java-properties"
            path="./syntaxes/JavaProperties.tmLanguage" >
      </grammar>      
      <scopeNameContentTypeBinding
            contentTypeId="org.springframework.boot.ide.properties.application.properties"
            scopeName="source.java-properties">
      </scopeNameContentTypeBinding>
   </extension>
   
   
   <extension
      id="springxml-completion-computer"
      point="org.eclipse.wst.sse.ui.completionProposal">         

      <proposalCategory 
            id="org.springframework.boot.ide.xmlconfig.contentassist"
            name="Spring XML Content Assist">
      </proposalCategory>

      <proposalComputer
            activate="true"
            categoryId="org.springframework.boot.ide.xmlconfig.contentassist"
            class="org.springframework.tooling.boot.ls.xml.XMLContentAssistProposalComputer"
            id="org.springframework.boot.ide.xmlconfig.contentassist.proposalcomputer">
         <contentType id="org.springframework.boot.ide.xmlconfig"/>
      </proposalComputer>

   </extension>

   <!-- what is this for? Commented it out but everything seems to work
   <extension
         point="org.eclipse.core.filebuffers.documentSetup">
      <participant
            class="org.eclipse.lsp4e.ConnectDocumentToLanguageServerSetupParticipant"
            contentTypeId="org.springframework.boot.ide.properties.application.properties">
      </participant>
   </extension>
   <extension
         point="org.eclipse.core.filebuffers.documentSetup">
      <participant
            class="org.eclipse.lsp4e.ConnectDocumentToLanguageServerSetupParticipant"
            contentTypeId="org.springframework.boot.ide.properties.application.yml">
      </participant>
   </extension>
   <extension
         point="org.eclipse.core.filebuffers.documentSetup">
      <participant
            class="org.eclipse.lsp4e.ConnectDocumentToLanguageServerSetupParticipant"
            contentTypeId="org.springframework.boot.ide.xmlconfig">
      </participant>
   </extension>
   -->

   <extension
         point="org.eclipse.ui.quickAccess">
      <computer
            class="org.springframework.tooling.boot.ls.commands.LiveProcessCommandsQuickAccessProvider"
            name="Spring - Live Process Information"
            requiresUIAccess="false"/>
   </extension>

</plugin>
