mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
Added support for editor open, close, update
This commit is contained in:
parent
ba6a21b00c
commit
cc9cbc07c5
4 changed files with 106 additions and 11 deletions
|
@ -27,6 +27,8 @@ import org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions
|
|||
import org.eclipse.xtext.resource.impl.ProjectDescription
|
||||
import org.eclipse.xtext.resource.impl.ResourceDescriptionsData
|
||||
import org.eclipse.xtext.validation.Issue
|
||||
import org.eclipse.xtext.resource.IExternalContentSupport
|
||||
import org.eclipse.xtext.resource.IExternalContentSupport.IExternalContentProvider
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -37,6 +39,7 @@ class WorkspaceManager {
|
|||
@Inject protected Provider<XtextResourceSet> resourceSetProvider
|
||||
@Inject protected IResourceServiceProvider.Registry languagesRegistry
|
||||
@Inject protected IFileSystemScanner fileSystemScanner
|
||||
@Inject protected IExternalContentSupport externalContentSupport
|
||||
|
||||
IndexState indexState = new IndexState
|
||||
URI baseDir
|
||||
|
@ -81,6 +84,7 @@ class WorkspaceManager {
|
|||
def didOpen(DidOpenTextDocumentParams changeEvent) {
|
||||
val uri = toUri(changeEvent.textDocument.uri)
|
||||
openDocuments.put(uri, new Document(changeEvent.textDocument.version, changeEvent.textDocument.text))
|
||||
doBuild(#[uri], newArrayList)
|
||||
}
|
||||
|
||||
def URI toUri(String path) {
|
||||
|
@ -93,7 +97,8 @@ class WorkspaceManager {
|
|||
|
||||
def didClose(DidCloseTextDocumentParams changeEvent) {
|
||||
val uri = toUri(changeEvent.textDocument.uri)
|
||||
openDocuments.remove(uri)
|
||||
openDocuments.remove(uri)
|
||||
doBuild(#[uri], newArrayList)
|
||||
}
|
||||
|
||||
def didSave(DidSaveTextDocumentParams changeEvent) {
|
||||
|
@ -123,9 +128,23 @@ class WorkspaceManager {
|
|||
projectDescription.attachToEmfObject(it)
|
||||
val index = new ChunkedResourceDescriptions(emptyMap, it)
|
||||
index.setContainer(projectDescription.name, newIndex)
|
||||
externalContentSupport.configureResourceSet(it, new IExternalContentProvider() {
|
||||
|
||||
override getActualContentProvider() {
|
||||
return this
|
||||
}
|
||||
|
||||
override getContent(URI uri) {
|
||||
openDocuments.get(uri)?.contents
|
||||
}
|
||||
|
||||
override hasContent(URI uri) {
|
||||
openDocuments.containsKey(uri)
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ import java.util.List
|
|||
import java.util.Map
|
||||
import org.eclipse.xtext.ide.server.LanguageServerImpl
|
||||
import org.eclipse.xtext.ide.server.ServerModule
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
||||
import org.eclipse.xtext.resource.FileExtensionProvider
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.util.Files
|
||||
import org.junit.Before
|
||||
|
||||
|
@ -62,4 +65,8 @@ class AbstractLanguageServerTest implements NotificationCallback<PublishDiagnost
|
|||
diagnostics.put(t.uri, t.diagnostics)
|
||||
}
|
||||
|
||||
@Inject def voidRegisterTestLanguage(IResourceServiceProvider.Registry registry) {
|
||||
val injector = new TestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration
|
||||
registry.extensionToFactoryMap.put(injector.getInstance(FileExtensionProvider).primaryFileExtension, injector.getInstance(IResourceServiceProvider))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*******************************************************************************
|
||||
* 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.ide.tests.server
|
||||
|
||||
import io.typefox.lsapi.DidChangeWatchedFilesParamsImpl
|
||||
import io.typefox.lsapi.DidCloseTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.DidOpenTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.FileEvent
|
||||
import io.typefox.lsapi.FileEventImpl
|
||||
import io.typefox.lsapi.InitializeParamsImpl
|
||||
import io.typefox.lsapi.TextDocumentIdentifierImpl
|
||||
import io.typefox.lsapi.TextDocumentItemImpl
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
class OpenDocumentTest extends AbstractLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testOpenDocument() {
|
||||
val firstFile = 'MyType1.testlang' -> '''
|
||||
type Test {
|
||||
NonExisting foo
|
||||
}
|
||||
'''
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.get(firstFile).head.message)
|
||||
|
||||
val path = 'MyType2.testlang' -> '''
|
||||
type Foo {
|
||||
}
|
||||
'''
|
||||
languageServer.getWorkspaceService.didChangeWatchedFiles(new DidChangeWatchedFilesParamsImpl => [
|
||||
changes = newArrayList(new FileEventImpl => [
|
||||
uri = path
|
||||
type = FileEvent.TYPE_CREATED
|
||||
])
|
||||
])
|
||||
|
||||
// still errorneous
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.get(firstFile).head.message)
|
||||
|
||||
// let's open the document with a different content
|
||||
languageServer.didOpen(new DidOpenTextDocumentParamsImpl => [
|
||||
textDocument = new TextDocumentItemImpl => [
|
||||
uri = path
|
||||
version = 1
|
||||
text = '''
|
||||
type NonExisting {
|
||||
}
|
||||
'''
|
||||
]
|
||||
])
|
||||
assertNull(diagnostics.get(firstFile).head)
|
||||
|
||||
// let's close again
|
||||
languageServer.didClose(new DidCloseTextDocumentParamsImpl => [
|
||||
textDocument = new TextDocumentIdentifierImpl => [
|
||||
uri = path
|
||||
]
|
||||
])
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.get(firstFile).head.message)
|
||||
}
|
||||
|
||||
}
|
|
@ -7,14 +7,10 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.tests.server
|
||||
|
||||
import com.google.inject.Inject
|
||||
import io.typefox.lsapi.DidChangeWatchedFilesParamsImpl
|
||||
import io.typefox.lsapi.FileEvent
|
||||
import io.typefox.lsapi.FileEventImpl
|
||||
import io.typefox.lsapi.InitializeParamsImpl
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
||||
import org.eclipse.xtext.resource.FileExtensionProvider
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
@ -24,11 +20,6 @@ import static org.junit.Assert.*
|
|||
*/
|
||||
class ServerTest extends AbstractLanguageServerTest {
|
||||
|
||||
@Inject def voidRegisterTestLanguage(IResourceServiceProvider.Registry registry) {
|
||||
val injector = new TestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration
|
||||
registry.extensionToFactoryMap.put(injector.getInstance(FileExtensionProvider).primaryFileExtension, injector.getInstance(IResourceServiceProvider))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testInitializeBuild() {
|
||||
'MyType1.testlang' -> '''
|
||||
|
@ -81,4 +72,6 @@ class ServerTest extends AbstractLanguageServerTest {
|
|||
assertTrue(diagnostics.values.join(','), diagnostics.values.forall[empty])
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue