-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add File System Path to the Content Roots (#1827)
- Loading branch information
Showing
17 changed files
with
293 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 95 additions & 36 deletions
131
engine/language-server/src/main/scala/org/enso/languageserver/filemanager/ContentRoot.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,128 @@ | ||
package org.enso.languageserver.filemanager | ||
|
||
import enumeratum._ | ||
import io.circe.syntax.EncoderOps | ||
import io.circe.{Encoder, Json} | ||
|
||
import java.io.File | ||
import java.util.UUID | ||
|
||
/** A representation of a content root. | ||
* | ||
* @param id the unique identifier of the content root | ||
* @param type the type of the content root | ||
* @param name The name of the content root | ||
*/ | ||
case class ContentRoot(id: UUID, `type`: ContentRootType, name: String) | ||
/** A representation of a content root. */ | ||
sealed trait ContentRoot { | ||
|
||
/** The type of entity that the content root represents. | ||
*/ | ||
sealed trait ContentRootType extends EnumEntry | ||
object ContentRootType extends Enum[ContentRootType] with CirceEnum[ContentRootType] { | ||
/** The unique identifier of the content root. */ | ||
def id: UUID | ||
} | ||
|
||
/** The content root represents the root of the current Enso project. | ||
object ContentRoot { | ||
|
||
/** A filesystem root. | ||
* | ||
* @param id the unique identifier of the content root | ||
* @param path absolute path of the content root | ||
*/ | ||
case object Project extends ContentRootType | ||
case class FileSystemRoot(override val id: UUID, path: String) | ||
extends ContentRoot | ||
|
||
/** The content root represents a system root (`/` on unix, drives on | ||
* windows). | ||
/** A root representing user's home on the filesystem. | ||
* | ||
* There may be multiple of this type of root sent by default. | ||
* @param id the unique identifier of the content root | ||
*/ | ||
case object Root extends ContentRootType | ||
case class Home(override val id: UUID) extends ContentRoot | ||
|
||
/** The content root represents the user's home directory. | ||
/** Main project root. | ||
* | ||
* @param id the unique identifier of the content root | ||
*/ | ||
case object Home extends ContentRootType | ||
case class Project(override val id: UUID) extends ContentRoot | ||
|
||
/** The content root represents an Enso library. | ||
/** A root of an imported library. | ||
* | ||
* @param id the unique identifier of the content root | ||
* @param namespace namespace of the library | ||
* @param name name of the library | ||
* @param version version of the library | ||
*/ | ||
case object Library extends ContentRootType | ||
case class Library( | ||
override val id: UUID, | ||
namespace: String, | ||
name: String, | ||
version: String | ||
) extends ContentRoot | ||
|
||
/** The content root was a custom location added by the IDE. | ||
/** A custom root, currently not used. | ||
* | ||
* @param id the unique identifier of the content root | ||
*/ | ||
case object Custom extends ContentRootType | ||
case class Custom(override val id: UUID) extends ContentRoot | ||
|
||
private object CodecField { | ||
val Id = "id" | ||
val Type = "type" | ||
val Namespace = "namespace" | ||
val Name = "name" | ||
val Version = "version" | ||
val Path = "path" | ||
} | ||
|
||
private object CodecType { | ||
val FileSystemRoot = "FileSystemRoot" | ||
val Home = "Home" | ||
val Project = "Project" | ||
val Library = "Library" | ||
val Custom = "Custom" | ||
} | ||
|
||
/** Necessary for Enumeratum and Circe. */ | ||
override val values = findValues | ||
/** An [[Encoder]] instance for [[ContentRoot]]. */ | ||
implicit val encoder: Encoder[ContentRoot] = { | ||
case FileSystemRoot(id, path) => | ||
Json.obj( | ||
CodecField.Type -> CodecType.FileSystemRoot.asJson, | ||
CodecField.Id -> id.asJson, | ||
CodecField.Path -> path.asJson | ||
) | ||
case Home(id) => | ||
Json.obj( | ||
CodecField.Type -> CodecType.Home.asJson, | ||
CodecField.Id -> id.asJson | ||
) | ||
case Project(id) => | ||
Json.obj( | ||
CodecField.Type -> CodecType.Project.asJson, | ||
CodecField.Id -> id.asJson | ||
) | ||
case Library(id, namespace, name, version) => | ||
Json.obj( | ||
CodecField.Type -> CodecType.Library.asJson, | ||
CodecField.Id -> id.asJson, | ||
CodecField.Namespace -> namespace.asJson, | ||
CodecField.Name -> name.asJson, | ||
CodecField.Version -> version.asJson | ||
) | ||
case Custom(id) => | ||
Json.obj( | ||
CodecField.Type -> CodecType.Custom.asJson, | ||
CodecField.Id -> id.asJson | ||
) | ||
} | ||
} | ||
|
||
/** A representation of a content root. | ||
/** A representation of a content root with a file that represents its | ||
* filesystem location | ||
* | ||
* @param id the unique identifier of the content root | ||
* @param `type` the type of the content root | ||
* @param name The name of the content root | ||
* @param contentRoot the raw content root | ||
* @param file the file on the filesystem that is the content root | ||
*/ | ||
case class ContentRootWithFile( | ||
id: UUID, | ||
`type`: ContentRootType, | ||
name: String, | ||
contentRoot: ContentRoot, | ||
file: File | ||
) { | ||
|
||
/** The unique identifier of the content root. */ | ||
def id: UUID = contentRoot.id | ||
|
||
/** Convert this to a content root for use in the protocol. | ||
* | ||
* @return a protocol content root | ||
*/ | ||
def toContentRoot: ContentRoot = { | ||
ContentRoot(id, `type`, name) | ||
} | ||
def toContentRoot: ContentRoot = contentRoot | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.