Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1130)

Side by Side Diff: Source/devtools/front_end/search/SourcesSearchScope.js

Issue 376163002: DevTools: Search across files should work for file:folderName queries. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added test Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/sdk/Workspace.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 var projects = this._projects(); 105 var projects = this._projects();
106 var barrier = new CallbackBarrier(); 106 var barrier = new CallbackBarrier();
107 var compositeProgress = new WebInspector.CompositeProgress(progress); 107 var compositeProgress = new WebInspector.CompositeProgress(progress);
108 for (var i = 0; i < projects.length; ++i) { 108 for (var i = 0; i < projects.length; ++i) {
109 var project = projects[i]; 109 var project = projects[i];
110 var weight = project.uiSourceCodes().length; 110 var weight = project.uiSourceCodes().length;
111 var projectProgress = new WebInspector.CompositeProgress(compositePr ogress.createSubProgress(weight)); 111 var projectProgress = new WebInspector.CompositeProgress(compositePr ogress.createSubProgress(weight));
112 var findMatchingFilesProgress = projectProgress.createSubProgress(); 112 var findMatchingFilesProgress = projectProgress.createSubProgress();
113 var searchContentProgress = projectProgress.createSubProgress(); 113 var searchContentProgress = projectProgress.createSubProgress();
114 var barrierCallback = barrier.createCallback(); 114 var barrierCallback = barrier.createCallback();
115 var callback = this._processMatchingFilesForProject.bind(this, this. _searchId, project, searchContentProgress, barrierCallback); 115 var filesMathingFileQuery = this._projectFilesMatchingFileQuery(proj ect, searchConfig);
116 project.findFilesMatchingSearchRequest(searchConfig, findMatchingFil esProgress, callback); 116 var callback = this._processMatchingFilesForProject.bind(this, this. _searchId, project, filesMathingFileQuery, searchContentProgress, barrierCallbac k);
117 project.findFilesMatchingSearchRequest(searchConfig, filesMathingFil eQuery, findMatchingFilesProgress, callback);
117 } 118 }
118 barrier.callWhenDone(this._searchFinishedCallback.bind(this, true)); 119 barrier.callWhenDone(this._searchFinishedCallback.bind(this, true));
119 }, 120 },
120 121
121 /** 122 /**
123 * @param {!WebInspector.Project} project
124 * @param {!WebInspector.ProjectSearchConfig} searchConfig
125 * @param {boolean=} dirtyOnly
126 * @return {!Array.<string>}
127 */
128 _projectFilesMatchingFileQuery: function(project, searchConfig, dirtyOnly)
129 {
130 var result = [];
131 var uiSourceCodes = project.uiSourceCodes();
132 for (var i = 0; i < uiSourceCodes.length; ++i) {
133 var uiSourceCode = uiSourceCodes[i];
134 if (dirtyOnly && !uiSourceCode.isDirty())
135 continue;
136 if (this._searchConfig.filePathMatchesFileQuery(uiSourceCode.fullDis playName()))
137 result.push(uiSourceCode.path());
138 }
139 result = result.sort(String.naturalOrderComparator);
140 return result;
141 },
142
143 /**
122 * @param {number} searchId 144 * @param {number} searchId
123 * @param {!WebInspector.Project} project 145 * @param {!WebInspector.Project} project
146 * @param {!Array.<string>} filesMathingFileQuery
124 * @param {!WebInspector.Progress} progress 147 * @param {!WebInspector.Progress} progress
125 * @param {function()} callback 148 * @param {function()} callback
126 * @param {!Array.<string>} files 149 * @param {!Array.<string>} files
127 */ 150 */
128 _processMatchingFilesForProject: function(searchId, project, progress, callb ack, files) 151 _processMatchingFilesForProject: function(searchId, project, filesMathingFil eQuery, progress, callback, files)
129 { 152 {
130 if (searchId !== this._searchId) { 153 if (searchId !== this._searchId) {
131 this._searchFinishedCallback(false); 154 this._searchFinishedCallback(false);
132 return; 155 return;
133 } 156 }
134 157
135 addDirtyFiles.call(this); 158 files = files.sort(String.naturalOrderComparator);
159 files = files.intersectOrdered(filesMathingFileQuery, String.naturalOrde rComparator);
160 files = files.concat(this._projectFilesMatchingFileQuery(project, this._ searchConfig, true));
apavlov 2014/07/09 14:00:20 This could be sorted as well
136 161
137 if (!files.length) { 162 if (!files.length) {
138 progress.done(); 163 progress.done();
139 callback(); 164 callback();
140 return; 165 return;
141 } 166 }
142 167
143 progress.setTotalWork(files.length); 168 progress.setTotalWork(files.length);
144 169
145 var fileIndex = 0; 170 var fileIndex = 0;
146 var maxFileContentRequests = 20; 171 var maxFileContentRequests = 20;
147 var callbacksLeft = 0; 172 var callbacksLeft = 0;
148 173
149 for (var i = 0; i < maxFileContentRequests && i < files.length; ++i) 174 for (var i = 0; i < maxFileContentRequests && i < files.length; ++i)
150 scheduleSearchInNextFileOrFinish.call(this); 175 scheduleSearchInNextFileOrFinish.call(this);
151 176
152 /** 177 /**
153 * @this {WebInspector.SourcesSearchScope}
154 */
155 function addDirtyFiles()
156 {
157 var matchingFiles = StringSet.fromArray(files);
158 var uiSourceCodes = project.uiSourceCodes();
159 for (var i = 0; i < uiSourceCodes.length; ++i) {
160 if (!uiSourceCodes[i].isDirty())
161 continue;
162 var path = uiSourceCodes[i].path();
163 if (!matchingFiles.contains(path) && this._searchConfig.filePath MatchesFileQuery(path))
164 files.push(path);
165 }
166 }
167
168 /**
169 * @param {string} path 178 * @param {string} path
170 * @this {WebInspector.SourcesSearchScope} 179 * @this {WebInspector.SourcesSearchScope}
171 */ 180 */
172 function searchInNextFile(path) 181 function searchInNextFile(path)
173 { 182 {
174 var uiSourceCode = project.uiSourceCode(path); 183 var uiSourceCode = project.uiSourceCode(path);
175 if (!uiSourceCode) { 184 if (!uiSourceCode) {
176 --callbacksLeft; 185 --callbacksLeft;
177 progress.worked(1); 186 progress.worked(1);
178 scheduleSearchInNextFileOrFinish.call(this); 187 scheduleSearchInNextFileOrFinish.call(this);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 264
256 /** 265 /**
257 * @param {!WebInspector.ProjectSearchConfig} searchConfig 266 * @param {!WebInspector.ProjectSearchConfig} searchConfig
258 * @return {!WebInspector.FileBasedSearchResultsPane} 267 * @return {!WebInspector.FileBasedSearchResultsPane}
259 */ 268 */
260 createSearchResultsPane: function(searchConfig) 269 createSearchResultsPane: function(searchConfig)
261 { 270 {
262 return new WebInspector.FileBasedSearchResultsPane(searchConfig); 271 return new WebInspector.FileBasedSearchResultsPane(searchConfig);
263 } 272 }
264 } 273 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/Workspace.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698