Skip to content

Commit 3b59669

Browse files
committed
Merge pull request #44 from my-personal-forks/fix-40-here-string
Fix #40 - here string
2 parents b9d5610 + bdbfaf3 commit 3b59669

File tree

7 files changed

+177
-26
lines changed

7 files changed

+177
-26
lines changed

README.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,34 @@ Support for the MS PowerShell programming language.
2222
- Python 3.3 (for build scripts)
2323

2424

25+
## Publishing This Package Locally as a Directory
26+
27+
**This is the recommended way of testing this package locally.**
28+
29+
First of all, you need to create a config file:
30+
31+
32+
```
33+
%HOME%/.sublime-package-dev
34+
```
35+
36+
Add this content:
37+
38+
```
39+
global-win editor ~/path/to/sublime_text.exe
40+
global-win installed-packages ~/path/to/sublime-text/Installed Packages
41+
```
42+
43+
1 Clone [this repo][this_repo] to a folder of your choice
44+
1. Make sure you have no *PowerShell.sublime-package* under the
45+
`{Data}/Installed Packages` directory.
46+
1. Run *./bin/Build-Folder.ps1* on the command line.
47+
48+
2549
## Generating `PowerShell.sublime-package`
2650

51+
**This method is not recommended at present.**
52+
2753
First of all, you need to create a config file:
2854

2955

@@ -61,10 +87,23 @@ is YAML format. To use this format, follow these steps:
6187
You will get and updated version of the plist file.
6288

6389

64-
[package_control]: https://sublime.wbond.net/installation
65-
[this_repo]: https://github.com/SublimeText/PowerShell
66-
[syntax_topic]: http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/extensibility/syntaxdefs.html
90+
## Running the Test Suite
91+
92+
### Requirements
93+
94+
- UnitTesting (install via [Package Control][package_control])
95+
96+
### How to Run the Tests
97+
98+
Open the command palette, then select 'UnitTesting'. Type in 'PowerShell' and
99+
press enter.
100+
67101

68102
## Contributing
69103

70104
See [CONTRIBUTING.md](CONTRIBUTING.md).
105+
106+
107+
[package_control]: https://sublime.wbond.net/installation
108+
[this_repo]: https://github.com/SublimeText/PowerShell
109+
[syntax_topic]: http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/extensibility/syntaxdefs.html

Support/PowershellSyntax.tmLanguage

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
</dict>
135135
<dict>
136136
<key>begin</key>
137-
<string>^@"\n</string>
137+
<string>\@"(?=\n)</string>
138138
<key>end</key>
139139
<string>^"@</string>
140140
<key>name</key>
@@ -155,6 +155,27 @@
155155
</dict>
156156
</array>
157157
</dict>
158+
<dict>
159+
<key>begin</key>
160+
<string>\@'(?=\n)</string>
161+
<key>end</key>
162+
<string>^'@</string>
163+
<key>name</key>
164+
<string>string.quoted.single.heredoc.powershell</string>
165+
<key>patterns</key>
166+
<array>
167+
<dict>
168+
<key>match</key>
169+
<string>''</string>
170+
<key>name</key>
171+
<string>constant.character.escape.powershell</string>
172+
</dict>
173+
</array>
174+
</dict>
175+
<dict>
176+
<key>include</key>
177+
<string>#numericConstant</string>
178+
</dict>
158179
<dict>
159180
<key>begin</key>
160181
<string>@\(</string>
@@ -203,27 +224,6 @@
203224
</dict>
204225
</array>
205226
</dict>
206-
<dict>
207-
<key>begin</key>
208-
<string>@'\n</string>
209-
<key>end</key>
210-
<string>^'@</string>
211-
<key>name</key>
212-
<string>string.quoted.single.heredoc.powershell</string>
213-
<key>patterns</key>
214-
<array>
215-
<dict>
216-
<key>match</key>
217-
<string>''</string>
218-
<key>name</key>
219-
<string>constant.character.escape.powershell</string>
220-
</dict>
221-
</array>
222-
</dict>
223-
<dict>
224-
<key>include</key>
225-
<string>#numericConstant</string>
226-
</dict>
227227
<dict>
228228
<key>match</key>
229229
<string>-([lg][te]|[ci]?(eq|ne))</string>

bin/Build-Folder.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
param([switch]$Release)
2+
3+
$script:thisDir = split-path $MyInvocation.MyCommand.Path -parent
4+
5+
. (join-path $script:thisDir "Config.ps1")
6+
7+
if(!$?){
8+
write-error "Could not read config."
9+
exit 1
10+
}
11+
12+
# copy to local folder
13+
push-location $thisDir
14+
push-location '..'
15+
$installedPackages = (GetConfigValue 'global-win' 'installed-packages')
16+
write-output "copying files..."
17+
# TODO: Perhaps we should delete the folder first.
18+
copy-item * -recurse -force -exclude ".git" "$installedPackages/../Packages/PowerShell"
19+
pop-location
20+
pop-location
21+
22+
write-output "restarting editor... bye!"
23+
start-sleep -milliseconds 100
24+
get-process "sublime_text" | stop-process
25+
start-sleep -milliseconds 250
26+
# sss
27+
$editor = (GetConfigValue 'global-win' 'editor')
28+
if(!$?){
29+
write-error "Could not locate editor command."
30+
exit 1
31+
}
32+
33+
&$editor

manifest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"*.sublime-workspace",
99
"*.sublime-project",
1010
"*.JSON-tmLanguage",
11+
"*.YAML-tmLanguage",
1112
"*.ps1",
1213
"*.hg*",
1314
"*.git*",
@@ -19,7 +20,8 @@
1920
["./tests/*.py", []],
2021

2122
["./Snippets/*.*", []],
22-
["./Support/*.*", []]
23+
["./Support/*.*", ["*.YAML-tmLanguage"]
24+
]
2325

2426
],
2527
"release": [
@@ -29,6 +31,7 @@
2931
"*.sublime-workspace",
3032
"*.sublime-project",
3133
"*.JSON-tmLanguage",
34+
"*.YAML-tmLanguage",
3235
"*.ps1",
3336
"*.hg*",
3437
"*.git*",

tests/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import unittest
2+
3+
import sublime
4+
5+
6+
class ViewTest(unittest.TestCase):
7+
def setUp(self):
8+
self.view = sublime.active_window().new_file()
9+
10+
def append(self, text):
11+
self.view.run_command('append', {'characters': text})
12+
13+
def tearDown(self):
14+
self.view.set_scratch(True)
15+
self.view.close()
16+
17+
18+
class SyntaxTest(ViewTest):
19+
def _setSyntax(self, rel_path):
20+
self.view.set_syntax_file(rel_path)
21+
22+
def getScopeNameAt(self, pt):
23+
return self.view.scope_name(pt)
24+
25+
def getFinestScopeNameAt(self, pt):
26+
return self.getScopeNameAt(pt).split()[-1]
27+
28+
def getScopeNameAtRowCol(self, row, col):
29+
text_pt = self.view.text_point(row, col)
30+
return self.getScopeNameAt(text_pt)
31+
32+
def getFinestScopeNameAtRowCol(self, row, col):
33+
return self.getScopeNameAtRowCol(row, col).split()[-1]
34+
35+
36+
class PowerShellSyntaxTest(SyntaxTest):
37+
def setUp(self):
38+
super().setUp()
39+
self._setSyntax('Packages/PowerShell/Support/PowershellSyntax.tmLanguage')

tests/syntax_def/__init__.py

Whitespace-only changes.

tests/syntax_def/test_syntax.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from PowerShell.tests import PowerShellSyntaxTest
2+
3+
4+
class Test_DoubleQuoted_HereDocStrings(PowerShellSyntaxTest):
5+
def testIsScopeCorrectIfDelimiterAtBOL(self):
6+
self.append("""@"
7+
hello
8+
"@
9+
""")
10+
sname = self.getFinestScopeNameAtRowCol(1, 1)
11+
self.assertEqual(sname, 'string.quoted.double.heredoc.powershell')
12+
13+
def testIsScopeCorrectIfDelimiterNotAtBOL(self):
14+
self.append("""$foo = @"
15+
hello
16+
"@
17+
""")
18+
sname = self.getFinestScopeNameAtRowCol(1, 1)
19+
self.assertEqual(sname, 'string.quoted.double.heredoc.powershell')
20+
21+
22+
class Test_SingleQuoted_HereDocStrings(PowerShellSyntaxTest):
23+
def testIsScopeCorrectIfDelimiterAtBOL(self):
24+
self.append("""@'
25+
hello
26+
'@
27+
""")
28+
sname = self.getFinestScopeNameAtRowCol(1, 1)
29+
self.assertEqual(sname, 'string.quoted.single.heredoc.powershell')
30+
31+
def testIsScopeCorrectIfDelimiterNotAtBOL(self):
32+
self.append("""$foo = @'
33+
hello
34+
'@
35+
""")
36+
sname = self.getFinestScopeNameAtRowCol(1, 1)
37+
self.assertEqual(sname, 'string.quoted.single.heredoc.powershell')

0 commit comments

Comments
 (0)