diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend index b2c676024..485ebf940 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend @@ -50,6 +50,7 @@ import io.typefox.lsapi.WorkspaceSymbolParams import java.util.List import org.eclipse.emf.common.util.URI import org.eclipse.xtend.lib.annotations.Accessors +import org.eclipse.xtext.findReferences.IReferenceFinder.IResourceAccess import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry import org.eclipse.xtext.ide.server.contentassist.ContentAssistService import org.eclipse.xtext.ide.server.symbol.DocumentSymbolService @@ -57,6 +58,7 @@ import org.eclipse.xtext.resource.IResourceServiceProvider import org.eclipse.xtext.validation.Issue import static io.typefox.lsapi.util.LsapiFactories.* +import org.eclipse.xtext.ide.server.findReferences.WorkspaceResourceAccess /** * @@ -67,6 +69,7 @@ import static io.typefox.lsapi.util.LsapiFactories.* InitializeParams params @Inject Provider workspaceManagerProvider WorkspaceManager workspaceManager + IResourceAccess resourceAccess @Inject extension UriExtensions @Inject extension IResourceServiceProvider.Registry languagesRegistry @@ -75,6 +78,7 @@ import static io.typefox.lsapi.util.LsapiFactories.* workspaceManager = workspaceManagerProvider.get val rootURI = URI.createFileURI(params.rootPath) workspaceManager.initialize(rootURI)[this.publishDiagnostics($0, $1)] + resourceAccess = new WorkspaceResourceAccess(workspaceManager) return new InitializeResultImpl => [ capabilities = new ServerCapabilitiesImpl => [ definitionProvider = true @@ -214,6 +218,7 @@ import static io.typefox.lsapi.util.LsapiFactories.* // end completion stuff // symbols + override definition(TextDocumentPositionParams params) { val uri = params.textDocument.uri.toUri val resourceServiceProvider = uri.resourceServiceProvider @@ -223,7 +228,7 @@ import static io.typefox.lsapi.util.LsapiFactories.* return workspaceManager.doRead(uri) [ document, resource | val offset = document.getOffSet(params.position) - return documentSymbolService.getDefinitions(resource, offset, workspaceManager) + return documentSymbolService.getDefinitions(resource, offset, resourceAccess) ] } @@ -236,14 +241,15 @@ import static io.typefox.lsapi.util.LsapiFactories.* return workspaceManager.doRead(uri) [ document, resource | val offset = document.getOffSet(params.position) - val indexData = workspaceManager.getIndexData(resource.URI) - + val definitions = if (params.context.includeDeclaration) - documentSymbolService.getDefinitions(resource, offset, workspaceManager) + documentSymbolService.getDefinitions(resource, offset, resourceAccess) else - emptyList - val references = documentSymbolService.getReferences(resource, offset, workspaceManager, indexData) + emptyList + + val indexData = workspaceManager.index + val references = documentSymbolService.getReferences(resource, offset, resourceAccess, indexData) val result = definitions + references return result.toList ] diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ProjectManager.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ProjectManager.xtend index 61fe77137..f02d868e4 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ProjectManager.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ProjectManager.xtend @@ -13,6 +13,7 @@ import java.util.List import java.util.Map import org.eclipse.emf.common.util.URI import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.xtend.lib.annotations.Accessors import org.eclipse.xtext.build.BuildRequest import org.eclipse.xtext.build.IncrementalBuilder import org.eclipse.xtext.build.IncrementalBuilder.Result @@ -24,10 +25,8 @@ import org.eclipse.xtext.resource.XtextResourceSet 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.util.IFileSystemScanner -import org.eclipse.xtend.lib.annotations.Accessors -import org.eclipse.xtext.resource.IResourceDescriptions +import org.eclipse.xtext.validation.Issue /** * @author Sven Efftinge - Initial contribution and API diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend index 24b5b4e2d..182ac3723 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend @@ -14,19 +14,17 @@ import java.util.ArrayList import java.util.List import java.util.Map import org.eclipse.emf.common.util.URI -import org.eclipse.xtext.findReferences.IReferenceFinder.IResourceAccess import org.eclipse.xtext.resource.IExternalContentSupport.IExternalContentProvider import org.eclipse.xtext.resource.XtextResource +import org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions import org.eclipse.xtext.resource.impl.ResourceDescriptionsData import org.eclipse.xtext.validation.Issue -import org.eclipse.xtext.util.concurrent.IUnitOfWork -import org.eclipse.emf.ecore.resource.ResourceSet import org.eclipse.xtext.resource.IResourceDescriptions /** * @author Sven Efftinge - Initial contribution and API */ -class WorkspaceManager implements IResourceAccess { +class WorkspaceManager { @Inject Provider projectManagerProvider Map baseDir2ProjectManager = newHashMap() @@ -70,6 +68,10 @@ class WorkspaceManager implements IResourceAccess { } } + def IResourceDescriptions getIndex() { + return new ChunkedResourceDescriptions(fullIndex) + } + def URI getProjectBaseDir(URI candidate) { for (projectBaseDir : baseDir2ProjectManager.keySet.sortBy[-toString.length]) { if (isPrefix(candidate, projectBaseDir)) { @@ -109,21 +111,14 @@ class WorkspaceManager implements IResourceAccess { } def T doRead(URI uri, (Document, XtextResource)=>T work) { - val projectMnr = getProjectManager(uri) - val doc = openDocuments.get(uri) - return work.apply(doc, projectMnr.getResource(uri) as XtextResource) + val resourceURI = uri.trimFragment + val projectMnr = getProjectManager(resourceURI) + val doc = openDocuments.get(resourceURI) + return work.apply(doc, projectMnr.getResource(resourceURI) as XtextResource) } def void doWrite(URI uri, (Document, XtextResource)=>T work) { } - - override readOnly(URI targetURI, IUnitOfWork work) { - return work.exec(targetURI.projectManager.resourceSet) - } - - def IResourceDescriptions getIndexData(URI targetURI) { - return targetURI.projectManager.indexState.resourceDescriptions - } } diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/findReferences/WorkspaceResourceAccess.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/findReferences/WorkspaceResourceAccess.xtend new file mode 100644 index 000000000..40fefc7ec --- /dev/null +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/findReferences/WorkspaceResourceAccess.xtend @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.server.findReferences + +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.resource.ResourceSet +import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor +import org.eclipse.xtext.findReferences.IReferenceFinder.IResourceAccess +import org.eclipse.xtext.ide.server.WorkspaceManager +import org.eclipse.xtext.util.concurrent.IUnitOfWork + +/** + * @author kosyakov - Initial contribution and API + */ +@FinalFieldsConstructor +class WorkspaceResourceAccess implements IResourceAccess { + + val WorkspaceManager workspaceManager + + override readOnly(URI targetURI, IUnitOfWork work) { + return workspaceManager.doRead(targetURI) [ document, resource | + return work.exec(resource.resourceSet) + ] + } + +}