Skip to content

Commit 9cb53b7

Browse files
committed
fix: sync the restored file and enable Find Usages when the LSP starts late
At app start a session-restored file is opened before the language server finishes starting, so the per-file setup it normally gets on a file switch never ran - jump-to-definition did nothing and "Find Usages" stayed disabled until the user switched files once. - DocumentSync.openSupportedDocuments now also didOpens the active editor's document (it may not yet be in getAllOpenDocuments() at server-start time), so the file the user is looking at is synced immediately. - FindReferencesManager refreshes the command's enabled state when a provider registers (the state is otherwise only computed on file switch), so a late-registering LSP references provider lights up "Find Usages" right away.
1 parent ce840d8 commit 9cb53b7

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/features/FindReferencesManager.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,22 @@ define(function (require, exports, module) {
3636
Strings = require("strings");
3737

3838
var _providerRegistrationHandler = new ProviderRegistrationHandler(),
39-
registerFindReferencesProvider = _providerRegistrationHandler.registerProvider.bind(
40-
_providerRegistrationHandler
41-
),
4239
removeFindReferencesProvider = _providerRegistrationHandler.removeProvider.bind(_providerRegistrationHandler);
4340

41+
/**
42+
* Register a find-references provider. The command's enabled state is normally computed on file
43+
* switch; a provider can register *after* the active file is already open (e.g. an LSP server
44+
* that starts asynchronously at app launch), so re-evaluate the menu state here too - otherwise
45+
* "Find All References" stays disabled until the user switches files.
46+
* @param {Object} providerInfo
47+
* @param {Array<string>} languageIds
48+
* @param {?number} priority
49+
*/
50+
function registerFindReferencesProvider(providerInfo, languageIds, priority) {
51+
_providerRegistrationHandler.registerProvider(providerInfo, languageIds, priority);
52+
setMenuItemStateForLanguage();
53+
}
54+
4455
var searchModel = new SearchModel(),
4556
_resultsView;
4657

src/languageTools/DocumentSync.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,17 @@ define(function (require, exports, module) {
191191
* @param {Object} client - a LanguageClient
192192
*/
193193
function openSupportedDocuments(client) {
194-
DocumentManager.getAllOpenDocuments().forEach(function (doc) {
194+
const docs = DocumentManager.getAllOpenDocuments().slice();
195+
// Belt-and-suspenders: the file the user is actually looking at - e.g. a session-restored
196+
// document at app start - may not yet appear in getAllOpenDocuments() at the moment the
197+
// server finishes starting. Include the active editor's document explicitly so it is synced
198+
// immediately, instead of only after the next file switch (which is what triggered the
199+
// activeEditorChange safety net before).
200+
const activeEditor = EditorManager.getActiveEditor();
201+
if (activeEditor && activeEditor.document && docs.indexOf(activeEditor.document) === -1) {
202+
docs.push(activeEditor.document);
203+
}
204+
docs.forEach(function (doc) {
195205
if (_isSupported(client, doc)) {
196206
// Always (re)send didOpen with the current content. This is called right after a
197207
// server (re)start, so any prior tracking is stale and must not be trusted - e.g.

0 commit comments

Comments
 (0)