[go: nahoru, domu]

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

Don't Suppress Errors When Creating Data Directory #1344

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: LogLevel) {
val log = LoggerFactory.getLogger(this.getClass)
log.trace("Initializing...")

val directoriesConfig =
DirectoriesConfig.initialize(serverConfig.contentRootPath)
val languageServerConfig = Config(
Map(serverConfig.contentRootUuid -> new File(serverConfig.contentRootPath)),
FileManagerConfig(timeout = 3.seconds),
PathWatcherConfig(),
ExecutionContextConfig(),
DirectoriesConfig(serverConfig.contentRootPath)
directoriesConfig
)
log.trace("Created Language Server config")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.enso.languageserver.filemanager.{
}

import scala.concurrent.duration._
import scala.util.Try

/** Configuration of the path watcher.
*
Expand Down Expand Up @@ -88,21 +87,34 @@ case class DirectoriesConfig(root: File) {
val suggestionsDatabaseFile: File =
new File(dataDirectory, DirectoriesConfig.SuggestionsDatabaseFile)

Try(Files.createDirectories(dataDirectory.toPath))
/** Create data directories if not exist. */
private def createDirectories(): Unit =
Files.createDirectories(dataDirectory.toPath)
}

object DirectoriesConfig {

val DataDirectory: String = ".enso"
val SuggestionsDatabaseFile: String = "suggestions.db"

/** Create default data directory config
/** Create default data directory config, creating directories if not exist.
*
* @param root the root directory path
* @return default data directory config
* @return data directory config
*/
def apply(root: String): DirectoriesConfig =
new DirectoriesConfig(new File(root))
def initialize(root: String): DirectoriesConfig =
initialize(new File(root))

/** Create default data directory config, creating directories if not exist.
*
* @param root the root directory path
* @return data directory config
*/
def initialize(root: File): DirectoriesConfig = {
val config = new DirectoriesConfig(root)
config.createDirectories()
config
}
}

/** The config of the running Language Server instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class ContextEventsListenerSpec
FileManagerConfig(timeout = 3.seconds),
PathWatcherConfig(),
ExecutionContextConfig(requestTimeout = 3.seconds),
DirectoriesConfig(root)
DirectoriesConfig.initialize(root)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class SuggestionsHandlerSpec
FileManagerConfig(timeout = 3.seconds),
PathWatcherConfig(),
ExecutionContextConfig(requestTimeout = 3.seconds),
DirectoriesConfig(root)
DirectoriesConfig.initialize(root)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BaseBinaryServerTest extends BinaryServerTestKit {
FileManagerConfig(timeout = 3.seconds),
PathWatcherConfig(),
ExecutionContextConfig(requestTimeout = 3.seconds),
DirectoriesConfig(testContentRoot.toFile)
DirectoriesConfig.initialize(testContentRoot.toFile)
)

sys.addShutdownHook(FileUtils.deleteQuietly(testContentRoot.toFile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BaseServerTest extends JsonRpcServerTestKit {
FileManagerConfig(timeout = 3.seconds),
PathWatcherConfig(),
ExecutionContextConfig(requestTimeout = 3.seconds),
DirectoriesConfig(testContentRoot.toFile)
DirectoriesConfig.initialize(testContentRoot.toFile)
)

override def protocol: Protocol = JsonRpc.protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FileManagerTest extends BaseServerTest with RetrySpec {
FileManagerConfig(timeout = 3.seconds),
PathWatcherConfig(),
ExecutionContextConfig(requestTimeout = 3.seconds),
DirectoriesConfig(directoriesDir.toFile)
DirectoriesConfig.initialize(directoriesDir.toFile)
)
}

Expand Down