Skip to content

Commit 7ae5535

Browse files
committed
- Issue #64, #65: Added TextRangeLegacy to allow transparent hosting on otherwise incompatible versions of N++
- Some code cleanup
1 parent 901b093 commit 7ae5535

File tree

18 files changed

+179
-130
lines changed

18 files changed

+179
-130
lines changed

bin/latest_version.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
1.7.20.0
2-
https://github.com/oleg-shilo/cs-script.npp/releases/download/v1.7.20.0
3-
Release v1.7.20.0
1+
v1.7.25.0
2+
https://github.com/oleg-shilo/cs-script.npp/releases/download/v1.7.25
3+
Release v1.7.25.0
44

5-
* Updated deployment algorithm to handle breaking changes in Notepad++ v7.5.9 hosting model.
5+
- Added integration with .NET 5 edition of CS-Script.
6+
The script engine needs to be enabled from settings dialog (see "Enable .NET 5/Core integration")

bin/package.cmd

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ echo(
44
echo Patching host assemblies with the version info...
55

66
rem properly rename x86 and x64 host DLLs
7-
cscs -l ..\src\tools\set_host_version.cs
7+
cscs -l -dbg ..\src\tools\set_host_version.cs
88

99
echo(
1010
echo Clearing old files...
@@ -27,14 +27,14 @@ xcopy "..\src\output\plugins" ".\plugins" /s /Y
2727
del ".\plugins\original_*"
2828
del ".\plugins\*.zip"
2929

30+
3031
move latest_version.txt latest_version.txt_ >nul 2>&1
3132
move latest_version.pre.txt latest_version.pre.txt_ >nul 2>&1
3233
move latest_version_dbg.txt latest_version_dbg.txt_ >nul 2>&1
3334

35+
rem goto exit
3436
cd plugins
3537

36-
del CSScriptNpp\CSScriptNpp.dll
37-
3838
copy CSScriptNpp.x86.dll CSScriptNpp.dll
3939
"C:\Program Files\7-Zip\7z.exe" a ..\CSScriptNpp.x86.zip *.dll -x!CSScriptNpp.*.dll CSScriptNpp
4040

@@ -56,4 +56,5 @@ move latest_version.txt_ latest_version.txt >nul 2>&1
5656
move latest_version.pre.txt_ latest_version.pre.txt >nul 2>&1
5757
move latest_version_dbg.txt_ latest_version_dbg.txt >nul 2>&1
5858

59-
pause
59+
pause
60+
:exit

bin/package.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
void main(string[] args)
99
{
1010
var version = AssemblyName.GetAssemblyName(@".\plugins\CSScriptNpp\CSScriptNpp.asm.dll").Version.ToString();
11+
// var hostVersion = AssemblyName.GetAssemblyName(@"..\src\NppPlugin.Host\output\NppPlugin.host.dll").Version.ToString();
1112
// var version = Directory.GetFiles(".", "CSScriptNpp.*.msi").Select(x => Path.GetFileNameWithoutExtension(x)).First().Replace("CSScriptNpp.", "");
1213

1314
Console.WriteLine("Injecting version into file names: " + version);

src/CSScriptIntellisense/AutocompleteForm.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using Intellisense.Common;
2-
using CSScriptIntellisense.Interop;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.Diagnostics;
64
using System.Drawing;
75
using System.Linq;
86
using System.Text;
97
using System.Windows.Forms;
10-
using Res = CSScriptIntellisense.Images;
8+
using CSScriptIntellisense.Interop;
9+
using Intellisense.Common;
1110
using Kbg.NppPluginNET.PluginInfrastructure;
11+
using Res = CSScriptIntellisense.Images;
1212

1313
namespace CSScriptIntellisense
1414
{
@@ -221,8 +221,8 @@ public bool OnKeyDown(Keys key)
221221
else
222222
{
223223
if (key == Keys.Enter ||
224-
(key == Keys.Right && Config.Instance.UseArrowToAccept) ||
225-
(key == Keys.Tab && Config.Instance.UseTabToAccept))
224+
(key == Keys.Right && Config.Instance.UseArrowToAccept) ||
225+
(key == Keys.Tab && Config.Instance.UseTabToAccept))
226226
{
227227
OnAutocompletionAccepted(selectedSuggestion as ICompletionData);
228228
Dispatcher.Schedule(10, Close);

src/CSScriptIntellisense/CSScriptIntellisense.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<AssemblyName>CSScriptIntellisense</AssemblyName>
1313
<StartupObject>
1414
</StartupObject>
15-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
15+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1616
<FileUpgradeFlags>
1717
</FileUpgradeFlags>
1818
<OldToolsVersion>3.5</OldToolsVersion>

src/CSScriptIntellisense/CSharpIntellisense/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Kbg.NppPluginNET.PluginInfrastructure;
21
using System;
32
using System.Diagnostics;
43
using System.IO;
54
using System.Linq;
65
using System.Windows.Forms;
6+
using Kbg.NppPluginNET.PluginInfrastructure;
77

88
namespace CSScriptIntellisense
99
{
Binary file not shown.

src/CSScriptIntellisense/CodeSnippets/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CSScriptIntellisense/Images/Images.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CSScriptIntellisense/Interop/NppExtensions.cs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Kbg.NppPluginNET.PluginInfrastructure;
21
using System;
32
using System.Collections.Generic;
43
using System.Drawing;
@@ -7,6 +6,7 @@
76
using System.Text;
87
using System.Text.RegularExpressions;
98
using System.Windows.Forms;
9+
using Kbg.NppPluginNET.PluginInfrastructure;
1010

1111
namespace CSScriptIntellisense
1212
{
@@ -74,11 +74,7 @@ static public string GetTextBetween(this ScintillaGateway document, int start, i
7474
if (end == -1)
7575
end = document.GetLength();
7676

77-
using (var tr = new TextRange(start, end, end - start + 1)) //+1 for null termination
78-
{
79-
document.GetTextRange(tr);
80-
return tr.lpstrText;
81-
}
77+
return document.get_text_range(start, end, end - start + 1); //+1 for null termination
8278
}
8379

8480
static public string TextBeforePosition(this IScintillaGateway document, int position, int maxLength)
@@ -91,13 +87,7 @@ static public string TextBeforePosition(this IScintillaGateway document, int pos
9187
int size = currentPos - startPos;
9288

9389
if (size > 0)
94-
{
95-
using (var tr = new TextRange(startPos, currentPos, bufCapacity))
96-
{
97-
document.GetTextRange(tr);
98-
return tr.lpstrText;
99-
}
100-
}
90+
return document.get_text_range(startPos, currentPos, bufCapacity);
10191
else
10292
return null;
10393
}
@@ -459,15 +449,41 @@ static public string TextAfterPosition(this ScintillaGateway document, int posit
459449
int size = endPos - startPos;
460450

461451
if (size > 0)
462-
{
463-
using (var tr = new TextRange(startPos, endPos, bufCapacity))
452+
return document.get_text_range(startPos, endPos, bufCapacity);
453+
else
454+
return null;
455+
}
456+
457+
static string get_text_range(this IScintillaGateway document, int startPos, int endPos, int bufCapacity)
458+
{
459+
var version = PluginBase.GetNppVersion();
460+
461+
// starting from v8.31 N++ uses Scintilla interface with TextRange min and max members as `IntPtr`
462+
// while previously they were `int`. If a wrong type passed N++ just crashes.
463+
464+
bool newNppVersion;
465+
if (version[0] > 8) // major version
466+
newNppVersion = true;
467+
else if (version[0] == 8)
468+
newNppVersion = version[1] >= 31; // minor version
469+
else
470+
newNppVersion = false;
471+
472+
if (Environment.GetEnvironmentVariable("CSSCRIPT_NPP_NEW_NPP_API") != null)
473+
newNppVersion = Environment.GetEnvironmentVariable("CSSCRIPT_NPP_NEW_NPP_API").ToLower() == "true";
474+
475+
if (newNppVersion)
476+
using (var tr = new TextRange((IntPtr)startPos, (IntPtr)endPos, bufCapacity))
464477
{
465478
document.GetTextRange(tr);
466479
return tr.lpstrText;
467480
}
468-
}
469481
else
470-
return null;
482+
using (var tr = new TextRangeLegacy(startPos, endPos, bufCapacity))
483+
{
484+
document.GetTextRangeLegacy(tr);
485+
return tr.lpstrText;
486+
}
471487
}
472488

473489
/// <summary>

0 commit comments

Comments
 (0)