cache-clearing-provider.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { Emitter, Point } = require('atom');
  2. // const path = require('path');
  3. function last (arr) {
  4. return arr[arr.length - 1];
  5. }
  6. module.exports = {
  7. packageName: 'symbol-provider-cache-clearing',
  8. name: 'Cache-clearing',
  9. isExclusive: false,
  10. canProvideSymbols (_meta) {
  11. return true;
  12. },
  13. onShouldClearCache (callback) {
  14. this.emitter ??= new Emitter;
  15. return this.emitter.on('should-clear-cache', callback);
  16. },
  17. getSymbols (meta) {
  18. let { editor, type } = meta;
  19. let results = [];
  20. setTimeout(() => {
  21. this.emitter.emit('should-clear-cache', { editor });
  22. }, 0);
  23. if (type === 'file') {
  24. results = [{
  25. position: new Point(1, 0),
  26. name: 'Transient symbol on row 2'
  27. }];
  28. } else if (type === 'project') {
  29. let root = last(atom.project.getPaths());
  30. let count = editor.getLineCount();
  31. // Put a symbol on every third line.
  32. for (let i = 0; i < count; i += 3) {
  33. results.push({
  34. position: new Point(i, 0),
  35. name: `Symbol on Row ${i + 1}`,
  36. directory: root,
  37. file: 'other-file.js'
  38. });
  39. }
  40. }
  41. return results;
  42. }
  43. };