Skip to content

Commit

Permalink
Fix quickly closing file after making changes removing contents from …
Browse files Browse the repository at this point in the history
…index

Relates to https://gitlab.com/Serenata/Serenata/issues/183 .

References #314 (though not the same issue)
  • Loading branch information
Gert-dev committed Jul 1, 2018
1 parent c3b4491 commit 3066834
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.1 (Unreleased)
* [Fix quickly closing a file still indexing it, but with no contents, removing contained structural elements](https://gitlab.com/Serenata/Serenata/issues/183)
* This was actually a bug in the client package, not the server.

## 4.2.0
* Update to Serenata [4.1.0](https://gitlab.com/Serenata/Serenata/tags/4.1.0)
* [Decaffeinate to switch to ES6 JavaScript from CoffeeScript](https://github.com/Gert-dev/php-ide-serenata/issues/375)
Expand Down
67 changes: 38 additions & 29 deletions lib/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1213,51 +1213,60 @@ You can do it via the menu Packages → Project Manager → Save Project.\
* @param {TextEditor} editor
*/
registerTextEditorListeners(editor) {
if (this.getConfiguration().get('general.indexContinuously') === true) {
// The default onDidStopChanging timeout is 300 milliseconds. As this is notcurrently configurable (and
// would also impact other packages), we install our own timeout on top of the existing one. This is useful
// for users that don't type particularly fast or are on slower machines and will prevent constant indexing
// from happening.
this.getDisposables().add(editor.onDidStopChanging(() => {
const path = editor.getPath();

return this.editorTimeoutMap[path] = setTimeout((() => {
this.onEditorDidStopChanging(editor);
this.editorTimeoutMap[path] = null;
}), this.getConfiguration().get('general.additionalIndexingDelay'));
if (this.getConfiguration().get('general.indexContinuously') !== true) {
this.getDisposables().add(editor.onDidSave(() => {
this.attemptCurrentProjectFileIndex(editor, editor.getPath(), editor.getBuffer().getText());
}));

this.getDisposables().add(editor.onDidChange(() => {
const path = editor.getPath();

if (this.editorTimeoutMap[path] != null) {
clearTimeout(this.editorTimeoutMap[path]);
this.editorTimeoutMap[path] = null;
}
}));
} else {
return this.getDisposables().add(editor.onDidSave(this.onEditorDidStopChanging.bind(this, editor)));
return;
}

// The default onDidStopChanging timeout is 300 milliseconds. As this is notcurrently configurable (and
// would also impact other packages), we install our own timeout on top of the existing one. This is useful
// for users that don't type particularly fast or are on slower machines and will prevent constant indexing
// from happening.
this.getDisposables().add(editor.onDidStopChanging(() => {
const path = editor.getPath();
const contents = editor.getBuffer().getText();

this.editorTimeoutMap[path] = setTimeout((() => {
this.attemptCurrentProjectFileIndex(editor, path, contents);
this.editorTimeoutMap[path] = null;
}), this.getConfiguration().get('general.additionalIndexingDelay'));
}));

this.getDisposables().add(editor.onDidChange(() => {
const path = editor.getPath();

if (this.editorTimeoutMap[path] != null) {
clearTimeout(this.editorTimeoutMap[path]);
this.editorTimeoutMap[path] = null;
}
}));
},

/**
* Invoked when an editor stops changing.
*
* @param {TextEditor} editor
* @param {TextEditor} editor
* @param {String|null} path
* @param {String} contents
*/
onEditorDidStopChanging(editor) {
const fileName = editor.getPath();

attemptCurrentProjectFileIndex(editor, path, contents) {
if (!/text.html.php$/.test(editor.getGrammar().scopeName)) {
return;
} else if (!fileName) {
} else if (!path) {
return;
}


console.log("index", path, contents);


const projectManager = this.getProjectManager();

if (projectManager.hasActiveProject() && projectManager.isFilePartOfCurrentProject(fileName)) {
return projectManager.attemptCurrentProjectFileIndex(fileName, editor.getBuffer().getText());
if (projectManager.hasActiveProject() && projectManager.isFilePartOfCurrentProject(path)) {
return projectManager.attemptCurrentProjectFileIndex(path, contents);
}
},

Expand Down

0 comments on commit 3066834

Please sign in to comment.