Skip to content

Commit

Permalink
Use :textual? flag for Search in Files (#7642)
Browse files Browse the repository at this point in the history
Technical note: we now look at `:textual?` flag of a resource type to determine if a resource without save data might be textual.

User-facing changes:

We no longer search through `.glb` files when performing Search in Files.

Fixes #7586
  • Loading branch information
vlaaad committed May 12, 2023
1 parent 6cffb3a commit 0afe9aa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion editor/src/clj/editor/defold_project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
;; Unregistered resources that are connected to the project
;; save-data input are assumed to produce text data.
(or (nil? resource-type)
(:textual? resource-type)))
(resource/textual-resource-type? resource-type)))

(defn write-save-data-to-disk! [save-data {:keys [render-progress!]
:or {render-progress! progress/null-render-progress!}
Expand Down
23 changes: 13 additions & 10 deletions editor/src/clj/editor/defold_project_search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
[{:keys [content resource] :as save-data}]
(or (when (some? content)
(make-line-coll #(BufferedReader. (StringReader. content))))
(when (and (resource/exists? resource) (not (text-util/binary? resource)))
(when (and (resource/exists? resource)
(if-let [resource-type (resource/resource-type resource)]
(resource/textual-resource-type? resource-type)
(not (text-util/binary? resource))))
(make-line-coll #(io/reader resource)))))

(defn compile-find-in-files-regex
Expand Down Expand Up @@ -86,15 +89,15 @@
(future
(try
(let [save-data (->> (into []
(keep (fn [node-id]
(let [save-data (g/node-value node-id :save-data evaluation-context)
resource (:resource save-data)]
(when (and (some? resource)
(not (resource/internal? resource))
(= :file (resource/source-type resource)))
save-data))))
(g/node-value project :nodes evaluation-context))
(sort-by save-data-sort-key))]
(keep (fn [node-id]
(let [save-data (g/node-value node-id :save-data evaluation-context)
resource (:resource save-data)]
(when (and (some? resource)
(not (resource/internal? resource))
(= :file (resource/source-type resource)))
save-data))))
(g/node-value project :nodes evaluation-context))
(sort-by save-data-sort-key))]
(ui/run-later
(project/update-system-cache-save-data! evaluation-context))
save-data)
Expand Down
1 change: 1 addition & 0 deletions editor/src/clj/editor/html.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
(workspace/register-resource-type workspace
:ext "html"
:label "HTML"
:textual? true
:node-type HtmlNode
:view-types [:html]
:view-opts nil))
1 change: 1 addition & 0 deletions editor/src/clj/editor/markdown.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
(workspace/register-resource-type workspace
:ext "md"
:label "Markdown"
:textual? true
:node-type MarkdownNode
:load-fn load-markdown
:view-types [:html :text]
Expand Down
11 changes: 11 additions & 0 deletions editor/src/clj/editor/resource.clj
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,17 @@
[resource]
(string/starts-with? (resource->proj-path resource) "/_defold"))

(defn textual-resource-type?
"Returns whether the resource type is marked as textual
Resource type is a required argument. If a resource does not specify a
resource type, you can use [[util.text-util/binary?]] to estimate if
the content of the resource is textual or not"
[resource-type]
{:pre [(some? resource-type)]
:post [(boolean? %)]}
(:textual? resource-type))

(def ^:private known-ext->language
;; See known language identifiers:
;; https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
Expand Down
5 changes: 3 additions & 2 deletions editor/src/clj/editor/workspace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ ordinary paths."
Optional kv-args:
:node-type a loaded resource node type; defaults to
editor.placeholder-resource/PlaceholderResourceNode
:textual? whether the resource is saved as text and needs proper
lf/crlf handling, default false
:textual? whether the resource is textual, default false. This
flag affects search in files availability for the
resource type and lf/crlf handling on save
:language language identifier string used for textual resources
that can be opened as code, used for LSP interactions,
see https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
Expand Down

0 comments on commit 0afe9aa

Please sign in to comment.