JavascriptLanguageExtension.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. /**
  7. * Resource extension that handles configuring the editor for Javascript
  8. */
  9. export default class JavascriptLanguageExtension implements Editor.ClientExtensions.WebViewService {
  10. name: string = "ClientJavascriptLanguageExtension";
  11. description: string = "Javascript language services for the editor.";
  12. private serviceLocator: Editor.ClientExtensions.ClientServiceLocator;
  13. /**
  14. * Initialize the language service
  15. * @param {Editor.ClientExtensions.ClientServiceLocator} serviceLocator
  16. */
  17. initialize(serviceLocator: Editor.ClientExtensions.ClientServiceLocator) {
  18. // initialize the language service
  19. this.serviceLocator = serviceLocator;
  20. }
  21. /**
  22. * Determines if the file name/path provided is something we care about
  23. * @param {string} path
  24. * @return {boolean}
  25. */
  26. private isValidFiletype(path: string): boolean {
  27. let ext = path.split(".").pop();
  28. return ext == "ts";
  29. }
  30. /**
  31. * Called when the editor needs to be configured for a particular file
  32. * @param {Editor.EditorEvents.EditorFileEvent} ev
  33. */
  34. configureEditor(ev: Editor.EditorEvents.EditorFileEvent) {
  35. if (this.isValidFiletype(ev.filename)) {
  36. let editor = <AceAjax.Editor>ev.editor;
  37. editor.session.setMode("ace/mode/javascript");
  38. }
  39. }
  40. }