Skip to content

Commit fcacd1b

Browse files
author
John Towers
committed
Merge branch 'release/0.0.9'
2 parents f5ebf47 + 037d83f commit fcacd1b

File tree

8 files changed

+226
-204
lines changed

8 files changed

+226
-204
lines changed

README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ Supports most useful CLI commands including:
1414
* Push\Pull source
1515
* Create Apex classes
1616
* Run tests for an org or specific class
17+
* Run SOQL query
18+
19+
This plugin also supports:
1720
* Code completion
1821
* Diagnostics
19-
Uses syntax highlighting from MavensMate
2022

2123
Language services (e.g., code completion and diagnostics) are provided by the [Apex Language Server](https://developer.salesforce.com/docs/atlas.en-us.sfdx_ide2.meta/sfdx_ide2/sfdx_ide2_build_app_apex_language_server_protocol.htm)
2224

@@ -25,12 +27,26 @@ Language services (e.g., code completion and diagnostics) are provided by the [A
2527
* `debug`: true or false to enable/disable printing debug statements to the sublime console
2628
* `java_home`: location of your java binary if it is not in your PATH
2729

30+
## Getting Started
31+
The plugin adds a new menu item (DXMate), context menu items, and command pallette items. Many of these are only enabled if you have an sfdx project currently opened.
32+
33+
If you don't have an sfdx proejct created, you can use DXMate > Project > Create Project to create one. If you do have one created, use Project > Add Folder to Project to add it to a project.
34+
35+
After that you can work with the rest of the commands (e.g., authorizing a dev hub and then creating a scratch org).
36+
2837
## To Do
2938
* Additional settings (e.g., disable language services)
3039
* Better handling of window opening (currently only starts language server if dx project is loaded when sublime is opened)
31-
* Additional language services
40+
* Add goto symbol definition from latest language server update
41+
* Add support for additional sfdx cli commands
42+
43+
## Compatibility
44+
This should be compatible with windows, osx and linux with ST3.
45+
46+
It's been tested on windows 10 and ubuntu 16.
3247

3348

3449
## Credits
35-
Most utility functions are based on or copied from [MavensMate](https://github.com/joeferraro/MavensMate-SublimeText)
36-
The LSP client code is cloned from the [Sublime LSP package](https://github.com/tomv564/LSP)
50+
* Most utility functions are based on or copied from [MavensMate](https://github.com/joeferraro/MavensMate-SublimeText). The syntax files for Apex are also from the MavensMate project.
51+
52+
* The LSP client code is adapted from the [Sublime LSP package](https://github.com/tomv564/LSP)

dxmate.py

+42-32
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .lib.threads import PanelThreadProgress
1414
from .lib.languageServer import *
1515
from .lib.event_hub import EventHub
16-
from .lib.util import *
16+
from .lib.util import util
1717
from .lib.diagnostic import *
1818
import ntpath
1919

@@ -120,11 +120,11 @@ def description(self):
120120
def plugin_loaded():
121121
global lsClient
122122
global printer
123-
if dxProjectFolder() != '':
123+
if util.dxProjectFolder() != '':
124124
lsClient = start_client()
125125
if lsClient is None:
126-
debug('Unable start langauge server')
127-
126+
util.debug('Unable start langauge server')
127+
EventHub.subscribe('on_load_async', set_syntax)
128128
active_window_id = sublime.active_window().id()
129129
printer = PanelPrinter.get(active_window_id)
130130
printer.write("sfdx plugin loaded", erase=True)
@@ -135,6 +135,14 @@ def plugin_unloaded():
135135
lsClient.kill()
136136

137137

138+
def set_syntax(view):
139+
if util.is_apex_file(view):
140+
util.debug('setting syntax for file')
141+
if "linux" in sys.platform or "darwin" in sys.platform:
142+
view.set_syntax_file(os.path.join("Packages",util.plugin_name(),"sublime","lang","Apex.sublime-syntax"))
143+
else:
144+
view.set_syntax_file(os.path.join("Packages/"+util.plugin_name()+"/sublime/lang/Apex.sublime-syntax"))
145+
138146
class ExitHandler(sublime_plugin.EventListener):
139147

140148
def on_window_commad(self, window, command_name, args):
@@ -179,13 +187,13 @@ def on_text_command(self, window, command_name, *args):
179187
else:
180188
EventHub.publish('on_window_command', window, command_name, *args)
181189
def on_modified_async(self, view):
182-
active_file_extension = file_extension(view)
190+
active_file_extension = util.file_extension(view)
183191
if active_file_extension != '.cls' and active_file_extension != '.trigger':
184192
return None
185193
EventHub.publish("on_modified_async", view)
186194

187195
def on_query_completions(self, view, prefix, locations):
188-
active_file_extension = file_extension(view)
196+
active_file_extension = util.file_extension(view)
189197
if active_file_extension != '.cls' and active_file_extension != '.trigger':
190198
return None
191199

@@ -205,7 +213,7 @@ def on_query_completions(self, view, prefix, locations):
205213
purge_did_change(view.buffer_id())
206214
client.send_request(
207215
Request.complete(
208-
get_document_position(view, locations[0])),
216+
util.get_document_position(view, locations[0])),
209217
self.handle_response)
210218
self.refreshing = False
211219
return self.completions, (sublime.INHIBIT_WORD_COMPLETIONS
@@ -247,8 +255,8 @@ def run_auto_complete(self):
247255
class DxmateRunFileTestsCommand(sublime_plugin.WindowCommand):
248256

249257
def run(self):
250-
self.dx_folder = dxProjectFolder()
251-
self.active_file = active_file()
258+
self.dx_folder = util.dxProjectFolder()
259+
self.active_file = util.active_file()
252260
self.active_file = ntpath.split(self.active_file)[
253261
1].replace('.cls', '')
254262
self.class_name = 'ApexClassName'
@@ -263,13 +271,13 @@ def run(self):
263271
PanelThreadProgress(t, 'Running Tests')
264272

265273
def is_enabled(self):
266-
self.dx_folder = dxProjectFolder()
274+
self.dx_folder = util.dxProjectFolder()
267275
if(self.dx_folder == ''):
268276
return False
269-
self.active_file = active_file()
277+
self.active_file = util.active_file()
270278
if not self.active_file.endswith('.cls'):
271279
return False
272-
if not file_is_test(self.window.active_view()):
280+
if not util.file_is_test(self.window.active_view()):
273281
return False
274282
return True
275283

@@ -300,7 +308,7 @@ class DxmateRunOrgTestsCommand(sublime_plugin.TextCommand):
300308

301309
def run(self, edit):
302310

303-
self.dx_folder = dxProjectFolder()
311+
self.dx_folder = util.dxProjectFolder()
304312
sublime.active_window().show_input_panel(
305313
'Org (leave blank for default)', '', self.run_tests, None, None)
306314

@@ -317,7 +325,7 @@ def run_tests(self, input):
317325
PanelThreadProgress(t, 'Running Org Tests')
318326

319327
def is_enabled(self):
320-
self.dx_folder = dxProjectFolder()
328+
self.dx_folder = util.dxProjectFolder()
321329
if self.dx_folder == '':
322330
return False
323331
return True
@@ -350,7 +358,7 @@ def run_command(self):
350358
class DxmatePushSourceCommand(sublime_plugin.TextCommand):
351359

352360
def run(self, edit):
353-
self.dx_folder = dxProjectFolder()
361+
self.dx_folder = util.dxProjectFolder()
354362
printer.show()
355363
printer.write('\nPushing Source')
356364
t = threading.Thread(target=self.run_command)
@@ -362,7 +370,7 @@ def run(self, edit):
362370
PanelThreadProgress(t, 'Source Pushed')
363371

364372
def is_enabled(self):
365-
self.dx_folder = dxProjectFolder()
373+
self.dx_folder = util.dxProjectFolder()
366374
if self.dx_folder == '':
367375
return False
368376
return True
@@ -394,7 +402,7 @@ def run_command(self):
394402
class DxmatePullSourceCommand(sublime_plugin.TextCommand):
395403

396404
def run(self, edit):
397-
self.dx_folder = dxProjectFolder()
405+
self.dx_folder = util.dxProjectFolder()
398406
printer.show()
399407
t = threading.Thread(target=self.run_command)
400408
t.start()
@@ -406,7 +414,7 @@ def run(self, edit):
406414
PanelThreadProgress(t, 'Source Pulled')
407415

408416
def is_enabled(self):
409-
self.dx_folder = dxProjectFolder()
417+
self.dx_folder = util.dxProjectFolder()
410418
if self.dx_folder == '':
411419
return False
412420
return True
@@ -438,7 +446,7 @@ def run_command(self):
438446
class DxmateOpenScratchOrgCommand(sublime_plugin.TextCommand):
439447

440448
def run(self, edit):
441-
self.dx_folder = dxProjectFolder()
449+
self.dx_folder = util.dxProjectFolder()
442450
printer.show()
443451
t = threading.Thread(target=self.run_command)
444452
t.start()
@@ -450,7 +458,7 @@ def run(self, edit):
450458
PanelThreadProgress(t, 'Org Opened')
451459

452460
def is_enabled(self):
453-
self.dx_folder = dxProjectFolder()
461+
self.dx_folder = util.dxProjectFolder()
454462
if self.dx_folder == '':
455463
return False
456464
return True
@@ -478,7 +486,7 @@ def run_command(self):
478486
class DxmateCreateScratchOrgCommand(sublime_plugin.TextCommand):
479487

480488
def run(self, edit):
481-
self.dx_folder = dxProjectFolder()
489+
self.dx_folder = util.dxProjectFolder()
482490
self.def_file = os.path.join(
483491
self.dx_folder, 'config', 'project-scratch-def.json')
484492
sublime.active_window().show_input_panel(
@@ -497,7 +505,7 @@ def create_org(self, input):
497505
PanelThreadProgress(t, 'Scratch Org Created')
498506

499507
def is_enabled(self):
500-
self.dx_folder = dxProjectFolder()
508+
self.dx_folder = util.dxProjectFolder()
501509
if self.dx_folder == '':
502510
return False
503511
return True
@@ -537,13 +545,13 @@ def run(self, edit):
537545
PanelThreadProgress(t, 'Auth Page Opened')
538546

539547
def is_enabled(self):
540-
dx_folder = dxProjectFolder()
548+
dx_folder = util.dxProjectFolder()
541549
if dx_folder == '':
542550
return False
543551
return True
544552

545553
def run_command(self):
546-
dx_folder = dxProjectFolder()
554+
dx_folder = util.dxProjectFolder()
547555
args = ['sfdx', 'force:auth:web:login', '-d', '-s', '-a', 'DevHub']
548556
startupinfo = None
549557
if os.name == 'nt':
@@ -570,7 +578,7 @@ def run(self):
570578
'Query', '', self.run_query, None, None)
571579

572580
def is_enabled(self, paths=[]):
573-
dx_folder = dxProjectFolder()
581+
dx_folder = util.dxProjectFolder()
574582
if(dx_folder == ''):
575583
return False
576584
return True
@@ -588,7 +596,7 @@ def run_query(self, input):
588596
PanelThreadProgress(t, 'Query run')
589597

590598
def run_command(self):
591-
dx_folder = dxProjectFolder()
599+
dx_folder = util.dxProjectFolder()
592600
args = ['sfdx', 'force:data:soql:query',
593601
'-q', self.query]
594602
startupinfo = None
@@ -608,9 +616,9 @@ def run_command(self):
608616
#try:
609617
# parsed = json.loads(content)
610618
# content = json.dumps(parsed, sort_keys=True,indent=1, separators=(',', ':'))
611-
# debug(content)
619+
# util.debug(content)
612620
#except Exception as e:
613-
# debug('could not format query results\n', e)
621+
# util.debug('could not format query results\n', e)
614622
file = sublime.active_window().new_file()
615623
file.set_scratch(True)
616624
file.set_name('SOQL')
@@ -639,7 +647,7 @@ def run(self, paths=[]):
639647
'Class Name', self.class_name, self.create_class, None, None)
640648

641649
def is_enabled(self, paths=[]):
642-
dx_folder = dxProjectFolder()
650+
dx_folder = util.dxProjectFolder()
643651
if(dx_folder == ''):
644652
return False
645653
if len(paths) != 1 or (len(paths) > 0 and os.path.isfile(paths[0])):
@@ -659,7 +667,7 @@ def create_class(self, input):
659667
PanelThreadProgress(t, 'Apex Class Created')
660668

661669
def run_command(self):
662-
dx_folder = dxProjectFolder()
670+
dx_folder = util.dxProjectFolder()
663671
args = ['sfdx', 'force:apex:class:create',
664672
'-n', self.class_name, '-d', self.class_dir]
665673
startupinfo = None
@@ -696,13 +704,13 @@ def run(self, edit):
696704
PanelThreadProgress(t, 'Project Upgraded')
697705

698706
def is_enabled(self):
699-
dx_folder = dxProjectFolder()
707+
dx_folder = util.dxProjectFolder()
700708
if dx_folder == '':
701709
return False
702710
return True
703711

704712
def run_command(self):
705-
dx_folder = dxProjectFolder()
713+
dx_folder = util.dxProjectFolder()
706714
args = ['sfdx', 'force:project:upgrade', '-f']
707715
startupinfo = None
708716
if os.name == 'nt':
@@ -782,3 +790,5 @@ def run_command(self):
782790
else:
783791
printer.write('\nError creating project:')
784792
printer.write('\n' + str(out, 'UTF-8'))
793+
794+

lib/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .util import util
2+
from .event_hub import EventHub
3+
_all_ = [
4+
'util',
5+
'EventHub'
6+
]

0 commit comments

Comments
 (0)