mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
[lsp] added IMimeTypeProvider, only highlight keywords starting with a letter, support non-incrmental updates
This commit is contained in:
parent
6643088e2b
commit
8d7e5d9724
5 changed files with 56 additions and 8 deletions
|
@ -65,7 +65,7 @@ interface IEditorHighlightingConfigurationProvider {
|
|||
|
||||
def Iterable<String> getKeywords() {
|
||||
GrammarUtil.containedKeywords(grammarAccess.grammar).filter [
|
||||
Character.isJavaIdentifierStart(it.value.charAt(0))
|
||||
Character.isLetter(it.value.charAt(0))
|
||||
].map[value].toSet.sort
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,13 @@ import org.eclipse.xtend.lib.annotations.Data
|
|||
def Document applyChanges(Iterable<? extends TextEdit> changes) {
|
||||
var newContent = contents
|
||||
for (change : changes) {
|
||||
val start = getOffSet(change.range.start)
|
||||
val end = getOffSet(change.range.end)
|
||||
newContent = newContent.substring(0, start) + change.newText + newContent.substring(end)
|
||||
if (change.range === null) {
|
||||
newContent = change.newText
|
||||
} else {
|
||||
val start = getOffSet(change.range.start)
|
||||
val end = getOffSet(change.range.end)
|
||||
newContent = newContent.substring(0, start) + change.newText + newContent.substring(end)
|
||||
}
|
||||
}
|
||||
return new Document(version + 1, newContent)
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ import org.eclipse.xtext.resource.IResourceServiceProvider
|
|||
import org.eclipse.xtext.validation.Issue
|
||||
|
||||
import static io.typefox.lsapi.util.LsapiFactories.*
|
||||
import org.eclipse.xtext.resource.IMimeTypeProvider
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -117,11 +118,13 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
result.supportedLanguages = newArrayList()
|
||||
for (serviceProvider : languagesRegistry.extensionToFactoryMap.values.filter(IResourceServiceProvider).toSet) {
|
||||
val extensionProvider = serviceProvider.get(FileExtensionProvider)
|
||||
val mimeTypesProvider = serviceProvider.get(IMimeTypeProvider)
|
||||
val langInfo = serviceProvider.get(LanguageInfo)
|
||||
val highlightingProvider = serviceProvider.get(IEditorHighlightingConfigurationProvider)
|
||||
val language = new LanguageDescriptionImpl => [
|
||||
fileExtensions = extensionProvider.fileExtensions.toList
|
||||
languageId = langInfo.languageName
|
||||
mimeTypes = mimeTypesProvider.mimeTypes
|
||||
if (highlightingProvider !== null)
|
||||
highlightingConfiguration = highlightingProvider.getConfiguration(params.clientName)
|
||||
]
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.resource
|
||||
|
||||
import com.google.inject.ImplementedBy
|
||||
import java.util.List
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
@ImplementedBy(DefaultImpl)
|
||||
interface IMimeTypeProvider {
|
||||
|
||||
def List<String> getMimeTypes()
|
||||
|
||||
static class DefaultImpl implements IMimeTypeProvider {
|
||||
|
||||
override getMimeTypes() {
|
||||
#[]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -96,12 +96,25 @@ class DocumentTest {
|
|||
]
|
||||
}
|
||||
|
||||
@Test def void testUpdate_nonIncrementalChange() {
|
||||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar''') => [
|
||||
assertEquals(' foo ', applyChanges(#[
|
||||
change(null, null, " foo ")
|
||||
]).contents)
|
||||
]
|
||||
}
|
||||
|
||||
private def change(PositionImpl startPos, PositionImpl endPos, String newText) {
|
||||
new TextEditImpl => [
|
||||
range = new RangeImpl => [
|
||||
start = startPos
|
||||
end = endPos
|
||||
]
|
||||
if (startPos !== null) {
|
||||
range = new RangeImpl => [
|
||||
start = startPos
|
||||
end = endPos
|
||||
]
|
||||
}
|
||||
it.newText = newText
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue