Skip to content
Merged
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
19 changes: 19 additions & 0 deletions Core/Sources/Service/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ final class Workspace {
"Suggestion feature is disabled for this project."
}
}

struct UnsupportedFileError: Error, LocalizedError {
var extensionName: String
var errorDescription: String? {
"File type \(extensionName) unsupported."
}
}

let projectRootURL: URL
let openedFileRecoverableStorage: OpenedFileRecoverableStorage
Expand Down Expand Up @@ -223,6 +230,11 @@ final class Workspace {
static func fetchOrCreateWorkspaceIfNeeded(fileURL: URL) async throws
-> (workspace: Workspace, filespace: Filespace)
{
let ignoreFileExtensions = ["mlmodel"]
if ignoreFileExtensions.contains(fileURL.pathExtension) {
throw UnsupportedFileError(extensionName: fileURL.pathExtension)
}

// If we know which project is opened.
if let currentProjectURL = try await Environment.fetchCurrentProjectRootURLFromXcode() {
if let existed = workspaces[currentProjectURL] {
Expand Down Expand Up @@ -401,6 +413,13 @@ extension Workspace {
refreshUpdateTime()
openedFileRecoverableStorage.openFile(fileURL: filespace.fileURL)
Task {
// check if file size is larger than 15MB, if so, return immediately
if let attrs = try? FileManager.default
.attributesOfItem(atPath: filespace.fileURL.path),
let fileSize = attrs[FileAttributeKey.size] as? UInt64,
fileSize > 15 * 1024 * 1024
{ return }

try await suggestionService?.notifyOpenTextDocument(
fileURL: filespace.fileURL,
content: try String(contentsOf: filespace.fileURL, encoding: .utf8)
Expand Down