Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor command lines #251

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
pwrightcertinia marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ lazy val apexls = crossProject(JSPlatform, JVMPlatform)
"com.github.nawforce" %%% "scala-json-rpc" % "1.1.0",
"com.github.nawforce" %%% "scala-json-rpc-upickle-json-serializer" % "1.1.0",
"com.lihaoyi" %%% "upickle" % "1.2.0",
"com.lihaoyi" %%% "mainargs" % "0.5.4",
"org.scalatest" %%% "scalatest" % "3.2.0" % Test
)
)
Expand Down
8 changes: 4 additions & 4 deletions js/npm/src/__tests__/system/SampleCheckSys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ describe("Check samples", () => {
[
"-cp",
"jvm/target/scala-2.13/*:jvm/target/scala-2.13/apex-ls_2.13-*.jar",
"io.github.apexdevtools.apexls.Main",
"-verbose",
"-nocache",
"-outlinemulti",
"io.github.apexdevtools.apexls.CheckForIssues",
"-d", "warnings",
"-n",
"-w",
path,
],
{
Expand Down
23 changes: 0 additions & 23 deletions jvm/src/main/scala/com/nawforce/apexlink/ApexLink.scala

This file was deleted.

57 changes: 42 additions & 15 deletions jvm/src/main/scala/com/nawforce/apexlink/api/Org.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.nawforce.apexlink.api

import com.nawforce.apexlink.org.OPM
import com.nawforce.apexlink.plugins.{PluginsManager, UnusedPlugin}
import com.nawforce.apexlink.rpc.{
BombScore,
ClassTestItem,
Expand All @@ -23,6 +24,7 @@ import com.nawforce.apexlink.rpc.{
HoverItem,
LocationLink,
MethodTestItem,
OpenOptions,
Rename,
TargetLocation
}
Expand All @@ -31,27 +33,21 @@ import com.nawforce.pkgforce.diagnostics.{IssuesManager, LoggerOps}
import com.nawforce.pkgforce.names.TypeIdentifier
import com.nawforce.pkgforce.path.{PathLike, PathLocation}
import com.nawforce.pkgforce.workspace.{ProjectConfig, Workspace}
import com.nawforce.runtime.platform.Path
import com.nawforce.runtime.platform.{Environment, Path}

/** A virtual Org used to present the analysis functionality in a familiar way.
*
* All analysis works within the context of a virtual Org. You can manage multiple of these at the
* same time but most use cases just need one creating, see Org.newOrg(). The Org functions as a
* container of multiple [[Package]] objects and maintains a set of discovered issues from the
* analysis of the package metadata. All orgs have at least one 'unmanaged' package identifiable by
* having no namespace.
* having no namespace. At any point you can list of current issues with the packages from
* getIssues. When you create an Org the metadata from the provided workspace directory will be
* loaded automatically, honouring the settings in sfdx-project.json & .forceignore files if present.
*
* In the simple case after creating an Org, you should add one or more packages detailing where
* package metadata is stored. Adding large packages can take considerable CPU and memory
* resources. Once the packages are loaded the metadata within them can be mutated using the
* [[Package]] methods. At any point you can list of current issues with the packages from
* getIssues.
*
* When metadata changes are requested (see [[Package.refresh]] they are queued for later
* processing either via calling [[Org.flush]] or via automatic flushing (the default). Flushing
* also updates a disk cache that helps significantly reduce initial loading times. The flushing
* model used by an [[Org]] is set on construction, see [[ServerOps.setAutoFlush]] to change to
* manual flushing.
* Changes made to the workspace metadata files are automatically handled, although there can be some
* lag in the file watching. You can also prompt for changes to be handled via [[Package.refresh]]
* to have better control over handling.
*
* Orgs and Packages are not thread safe, serialise all calls to them.
*/
Expand Down Expand Up @@ -250,13 +246,44 @@ trait Org {

object Org {

/** Create a new empty Org to which you can add packages for code analysis. */
/** Create a new virtual org for a workspace
* @param path workspace directory
*/
def newOrg(path: String): Org = {
newOrg(Path(path))
}

/** Create a new empty Org to which you can add packages for code analysis. */
/** Create a new virtual org for a workspace
* @param path workspace directory
*/
def newOrg(path: PathLike): Org = {
newOrg(path, OpenOptions.default())
}

/** Create a new virtual org for a workspace
* @param path workspace directory
* @param options org options
*/
def newOrg(path: PathLike, options: OpenOptions): Org = {
// All should be options on the org, some are cached when the org is created
options.loggingLevel.foreach(LoggerOps.setLoggingLevel)
options.parser.foreach(ServerOps.setCurrentParser)
options.externalAnalysisMode.foreach(mode =>
ServerOps.setExternalAnalysis(ExternalAnalysisConfiguration(mode))
)
options.cacheDirectory.foreach(path => {
Environment.setCacheDirOverride(Some(Some(Path(path))))
ServerOps.setAutoFlush(path.nonEmpty)
})
options.indexerConfiguration.foreach(values =>
ServerOps.setIndexerConfiguration(IndexerConfiguration(values._1, values._2))
)
options.autoFlush.foreach(enabled => ServerOps.setAutoFlush(enabled))
options.cache.foreach(enabled => if (!enabled) Environment.setCacheDirOverride(Some(None)))
options.unused.foreach(enabled =>
if (!enabled) PluginsManager.removePlugins(Seq(classOf[UnusedPlugin]))
)

LoggerOps.infoTime(
s"Org created",
show = true,
Expand Down
31 changes: 0 additions & 31 deletions jvm/src/main/scala/com/nawforce/apexlink/cmds/Server.scala

This file was deleted.

18 changes: 16 additions & 2 deletions jvm/src/main/scala/com/nawforce/apexlink/rpc/OrgAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ case class OpenOptions private (
parser: Option[String] = None,
loggingLevel: Option[String] = None,
externalAnalysisMode: Option[String] = None,
cache: Option[Boolean] = None,
cacheDirectory: Option[String] = None,
indexerConfiguration: Option[(Long, Long)] = None
indexerConfiguration: Option[(Long, Long)] = None,
autoFlush: Option[Boolean] = None,
unused: Option[Boolean] = None
) {
def withParser(name: String): OpenOptions = {
copy(parser = Some(name))
Expand All @@ -210,20 +213,31 @@ case class OpenOptions private (
copy(cacheDirectory = Some(path))
}

def withCache(enabled: Boolean): OpenOptions = {
copy(cache = Some(enabled))
}

def withIndexerConfiguration(
rescanTriggerTimeMs: Long,
quietPeriodForRescanMs: Long
): OpenOptions = {
copy(indexerConfiguration = Some((rescanTriggerTimeMs, quietPeriodForRescanMs)))
}

def withAutoFlush(enabled: Boolean): OpenOptions = {
copy(autoFlush = Some(enabled))
}

def withUnused(enabled: Boolean): OpenOptions = {
copy(unused = Some(enabled))
}
}

object OpenOptions {
implicit val rw: RW[OpenOptions] = macroRW

def default(): OpenOptions = {
new OpenOptions(None, None, None, None, None)
new OpenOptions()
}
}

Expand Down
29 changes: 6 additions & 23 deletions jvm/src/main/scala/com/nawforce/apexlink/rpc/OrgAPIImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

package com.nawforce.apexlink.rpc

import com.nawforce.apexlink.api.{
ExternalAnalysisConfiguration,
IndexerConfiguration,
Org,
ServerOps
}
import com.nawforce.apexlink.api.{ExternalAnalysisConfiguration, Org, ServerOps}
import com.nawforce.apexlink.org.{OPM, OrgInfo}
import com.nawforce.pkgforce.diagnostics.LoggerOps
import com.nawforce.pkgforce.names.TypeIdentifier
Expand All @@ -33,9 +28,9 @@ trait APIRequest {
def process(org: OrgQueue): Unit
}

class OrgQueue(path: String) {
class OrgQueue(path: String, options: OpenOptions) {
self =>
val org: Org = Org.newOrg(path)
val org: Org = Org.newOrg(Path(path), options)

private val queue = new LinkedBlockingQueue[APIRequest]()
private val dispatcher = new APIRequestDispatcher()
Expand Down Expand Up @@ -528,9 +523,9 @@ object GetTestMethodItems {
object OrgQueue {
private var _instance: Option[OrgQueue] = None

def open(path: String): OrgQueue = {
def open(path: String, options: OpenOptions = OpenOptions.default()): OrgQueue = {
synchronized {
_instance = Some(new OrgQueue(path))
_instance = Some(new OrgQueue(path, options))
_instance.get
}
}
Expand Down Expand Up @@ -574,19 +569,7 @@ class OrgAPIImpl extends OrgAPI {
}

override def open(directory: String, options: OpenOptions): Future[OpenResult] = {
options.loggingLevel.foreach(LoggerOps.setLoggingLevel)
options.parser.foreach(ServerOps.setCurrentParser)
options.externalAnalysisMode.foreach(mode =>
ServerOps.setExternalAnalysis(ExternalAnalysisConfiguration(mode))
)
options.cacheDirectory.foreach(path => {
Environment.setCacheDirOverride(Some(Some(Path(path))))
ServerOps.setAutoFlush(path.nonEmpty)
})
options.indexerConfiguration.foreach(values =>
ServerOps.setIndexerConfiguration(IndexerConfiguration(values._1, values._2))
)
OrgQueue.open(directory)
OrgQueue.open(directory, options)
OpenRequest(OrgQueue.instance())
}

Expand Down
Loading