[lsi] the full index access

Change-Id: Ic53435acd12521a193ea33a2e600e4c2b53266c9
Signed-off-by: akosyakov <anton.kosyakov@typefox.io>
This commit is contained in:
akosyakov 2016-05-27 09:07:14 +02:00
parent 924e37f435
commit b619a2314e
4 changed files with 55 additions and 24 deletions

View file

@ -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<WorkspaceManager> 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
]

View file

@ -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

View file

@ -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<ProjectManager> projectManagerProvider
Map<URI, ProjectManager> 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> 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 <T> void doWrite(URI uri, (Document, XtextResource)=>T work) {
}
override <R> readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
return work.exec(targetURI.projectManager.resourceSet)
}
def IResourceDescriptions getIndexData(URI targetURI) {
return targetURI.projectManager.indexState.resourceDescriptions
}
}

View file

@ -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 <R> readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
return workspaceManager.doRead(targetURI) [ document, resource |
return work.exec(resource.resourceSet)
]
}
}