Skip to content

Commit c010ae4

Browse files
committed
Update v1.3.4 to resolve issues
1 parent e21b5e9 commit c010ae4

File tree

13 files changed

+174
-92
lines changed

13 files changed

+174
-92
lines changed

package-lock.json

Lines changed: 30 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commandwindow/ExecutionCommandProvider.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ export default class ExecutionCommandProvider {
212212
const fileName = path.basename(editor.document.fileName);
213213
const filePath = editor.document.isUntitled ? fileName : path.basename(editor.document.fileName);
214214
const text = editor.document.getText();
215-
const lineRange = sectionData.sectionsTree.find(editor.selection.active.line);
216-
const sectionLineRanges = sectionData.sectionRanges.map((range) => [range.start.line + 1, range.end.line + 1]);
215+
const lineRange = sectionData.sectionsTree.find(editor.selection.active.line)?.range;
216+
const sectionLineRanges = sectionData.sectionRanges.map((section) => [section.range.start.line + 1, section.range.end.line + 1]);
217217

218218
if (lineRange === undefined) {
219219
return;
@@ -226,28 +226,47 @@ export default class ExecutionCommandProvider {
226226
return;
227227
}
228228

229-
const args: any[] = [
230-
fileName,
231-
filePath,
232-
text,
233-
lineRange.start.line + 1,
234-
lineRange.end.line + 1,
235-
-1,
236-
'vscode',
237-
'',
238-
false,
239-
false
240-
];
229+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
230+
let args: any[];
241231

242232
switch (this._mvm.getMatlabRelease()) {
243233
case undefined:
244234
case 'R2021b':
245235
case 'R2022a':
246236
case 'R2022b':
247-
case 'R2023a':
237+
case 'R2023a': {
238+
const splitLines = text.split(/\r\n|\r|\n/);
239+
const startPosition = splitLines.slice(0, lineRange.start.line).join('\n').length + 1;
240+
const executionLength = splitLines.slice(lineRange.start.line, lineRange.end.line + 1).join('\n').length + 1;
241+
242+
args = [
243+
fileName,
244+
filePath,
245+
text,
246+
startPosition,
247+
executionLength,
248+
-1,
249+
'vscode',
250+
'',
251+
false,
252+
false
253+
];
248254
break;
255+
}
249256
default:
250-
args.push(sectionLineRanges);
257+
args = [
258+
fileName,
259+
filePath,
260+
text,
261+
lineRange.start.line + 1,
262+
lineRange.end.line + 1,
263+
-1,
264+
'vscode',
265+
'',
266+
false,
267+
false,
268+
sectionLineRanges
269+
];
251270
break;
252271
}
253272

src/model/LineRangeTree.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
// Copyright 2024-2025 The MathWorks, Inc.
22
import * as vscode from 'vscode';
33

4+
export interface SectionData {
5+
range: vscode.Range
6+
isExplicit: boolean
7+
}
8+
49
/**
510
* A node used in the LineRangeTree.
611
* @class TreeNode
712
*/
813
class TreeNode {
9-
range: vscode.Range | undefined;
14+
range?: vscode.Range;
15+
section?: SectionData;
1016
children: TreeNode[];
1117
parent: TreeNode | undefined;
12-
constructor (range: vscode.Range | undefined) {
13-
this.range = range;
18+
constructor (section?: SectionData) {
19+
this.range = section?.range;
1420
this.children = [];
1521
this.parent = undefined;
22+
this.section = section;
1623
}
1724

1825
add (treeNode: TreeNode): void {
@@ -39,14 +46,14 @@ class TreeNode {
3946
export default class LineRangeTree {
4047
private _root: TreeNode | undefined;
4148

42-
constructor (sectonRanges: vscode.Range[]) {
43-
this._set(sectonRanges);
49+
constructor (sectons: SectionData[]) {
50+
this._set(sectons);
4451
}
4552

4653
/**
4754
* Creates a tree from the given section ranges array based on the start and end lines.
4855
*/
49-
_set (sectonRanges: vscode.Range[]): void {
56+
_set (sectonRanges: SectionData[]): void {
5057
this._root = new TreeNode(undefined);
5158
const objectLength = sectonRanges.length;
5259
let currentNode: TreeNode | undefined;
@@ -73,7 +80,7 @@ export default class LineRangeTree {
7380
* @param line number
7481
* @returns Section Range
7582
*/
76-
find (line: number): vscode.Range | undefined {
83+
find (line: number): SectionData | undefined {
7784
let currentNode: TreeNode | undefined;
7885

7986
currentNode = this._root;
@@ -83,7 +90,7 @@ export default class LineRangeTree {
8390
currentNode = this._searchByLine(line, currentNode);
8491
lastNode = currentNode ?? lastNode;
8592
}
86-
return (lastNode != null) ? lastNode.range : undefined;
93+
return (lastNode != null) ? lastNode.section : undefined;
8794
}
8895

8996
private _searchByLine (line: number, parentNode: TreeNode): TreeNode | undefined {

src/model/SectionModel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import * as vscode from 'vscode';
44
import Notification from '../Notifications'
5-
import LineRangeTree from './LineRangeTree';
5+
import LineRangeTree, { SectionData } from './LineRangeTree';
66
import { Notifier, Disposer } from '../commandwindow/Utilities';
77
import { EventEmitter } from 'events';
88

9+
export { SectionData };
10+
911
export interface SectionsData {
1012
uri: string
11-
sectionRanges: vscode.Range[]
13+
sectionRanges: SectionData[]
1214
sectionsTree?: LineRangeTree
1315
isDirty?: boolean
1416
}
@@ -50,7 +52,7 @@ export class SectionModel extends Disposer {
5052
return
5153
}
5254

53-
sectionsData.sectionRanges.sort((a: vscode.Range, b: vscode.Range) => a.start.line - b.start.line);
55+
sectionsData.sectionRanges.sort((a: SectionData, b: SectionData) => a.range.start.line - b.range.start.line);
5456
sectionsData.sectionsTree = new LineRangeTree(sectionsData.sectionRanges);
5557
sectionsData.isDirty = false;
5658

src/styling/SectionStylingService.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as vscode from 'vscode';
33

44
import { blueBorderTopDecoration, blueBorderBottomDecoration, greyBorderTopDecoration, greyBorderBottomDecoration, fontWeightBoldDecoration } from './Decorations';
5-
import { SectionModel, SectionsData } from '../model/SectionModel'
5+
import { SectionModel, SectionsData, SectionData } from '../model/SectionModel'
66
import { Disposer } from '../commandwindow/Utilities';
77
import { StartAndEndLines, TopAndBottomRanges, StylingRanges } from './StylingInterfaces';
88
let previousFocusedEditor: vscode.TextEditor | undefined;
@@ -105,7 +105,8 @@ export class SectionStylingService extends Disposer {
105105
*/
106106
private _highlightSections (editor: vscode.TextEditor, sections: SectionsData, activeCursorPosition: vscode.Position | null): void {
107107
const startAndEndLines = this._sectionsToStartAndEndLines(sections.sectionRanges);
108-
const allStartLinesRange = this._generateRanges(startAndEndLines.startLines);
108+
const explicitStartAndEndLines = this._sectionsToStartAndEndLines(sections.sectionRanges.filter((section) => section.isExplicit));
109+
const explicitSectionRanges = this._generateRanges(explicitStartAndEndLines.startLines);
109110
const lastLineinSection = startAndEndLines.endLines.sort((a, b) => a - b)[startAndEndLines.endLines.length - 1];
110111

111112
let stylingRanges: StylingRanges;
@@ -114,9 +115,9 @@ export class SectionStylingService extends Disposer {
114115
if (cursorPositionLine > lastLineinSection) {
115116
cursorPositionLine = lastLineinSection
116117
}
117-
const focusedSectionRange: vscode.Range | undefined = this._findFocusedSectionRange(sections, cursorPositionLine);
118-
if (focusedSectionRange !== undefined) {
119-
stylingRanges = this._getBlueAndGreyRanges(startAndEndLines, focusedSectionRange);
118+
const focusedSection = this._findFocusedSection(sections, cursorPositionLine);
119+
if (focusedSection !== undefined) {
120+
stylingRanges = this._getBlueAndGreyRanges(startAndEndLines, focusedSection);
120121
} else {
121122
stylingRanges = { blue: { top: [], bottom: [] }, grey: this._getGreyRanges(startAndEndLines) };
122123
}
@@ -125,12 +126,12 @@ export class SectionStylingService extends Disposer {
125126
}
126127
this._filterFirstAndLastSection(stylingRanges, lastLineinSection, editor.document);
127128

128-
this._setDecorations(editor, stylingRanges, allStartLinesRange);
129+
this._setDecorations(editor, stylingRanges, explicitSectionRanges);
129130
}
130131

131-
private _getBlueAndGreyRanges (startAndEndLines: StartAndEndLines, focusedSectionRange: vscode.Range): StylingRanges {
132-
const focusedStartLine = focusedSectionRange.start.line;
133-
const focusedEndLine = focusedSectionRange.end.line;
132+
private _getBlueAndGreyRanges (startAndEndLines: StartAndEndLines, focusedSectionRange: SectionData): StylingRanges {
133+
const focusedStartLine = focusedSectionRange.range.start.line;
134+
const focusedEndLine = focusedSectionRange.range.end.line;
134135
const { startLines, endLines } = startAndEndLines;
135136

136137
const startLinesWithoutFocusLine = startLines.filter((startLine) => {
@@ -181,32 +182,32 @@ export class SectionStylingService extends Disposer {
181182
return { top: this._generateRanges(startLines), bottom: this._generateRanges(endLinesFiltered) };
182183
}
183184

184-
private _setDecorations (editor: vscode.TextEditor, stylingRange: StylingRanges, allStartLinesRange: vscode.Range[]): void {
185+
private _setDecorations (editor: vscode.TextEditor, stylingRange: StylingRanges, explicitSectionRanges: vscode.Range[]): void {
185186
editor.setDecorations(blueBorderTopDecoration, stylingRange.blue.top);
186187
editor.setDecorations(blueBorderBottomDecoration, stylingRange.blue.bottom);
187188
editor.setDecorations(greyBorderTopDecoration, stylingRange.grey.top);
188189
editor.setDecorations(greyBorderBottomDecoration, stylingRange.grey.bottom);
189-
editor.setDecorations(fontWeightBoldDecoration, allStartLinesRange);
190+
editor.setDecorations(fontWeightBoldDecoration, explicitSectionRanges);
190191
}
191192

192193
private _generateRanges (lines: number[]): vscode.Range[] {
193194
return lines.map((line: number) => new vscode.Range(line, 0, line, Infinity));
194195
}
195196

196-
private _findFocusedSectionRange (sections: SectionsData, lineNumber: number): vscode.Range | undefined {
197-
let activeSection: vscode.Range | undefined;
197+
private _findFocusedSection (sections: SectionsData, lineNumber: number): SectionData | undefined {
198+
let activeSection: SectionData | undefined;
198199
if (lineNumber !== undefined && sections.sectionsTree !== undefined) {
199200
activeSection = sections.sectionsTree.find(lineNumber);
200201
}
201202
return activeSection;
202203
}
203204

204-
private _sectionsToStartAndEndLines (sectionRanges: vscode.Range[]): StartAndEndLines {
205+
private _sectionsToStartAndEndLines (sectionRanges: SectionData[]): StartAndEndLines {
205206
const startLines = new Set<number>();
206207
const endLines = new Set<number>();
207-
sectionRanges.forEach((sectionRange: vscode.Range) => {
208-
const startingIndex = sectionRange.start.line;
209-
const endingIndex = sectionRange.end.line;
208+
sectionRanges.forEach((sectionRange: SectionData) => {
209+
const startingIndex = sectionRange.range.start.line;
210+
const endingIndex = sectionRange.range.end.line;
210211
startLines.add(startingIndex);
211212
endLines.add(endingIndex);
212213
});

src/test/test-files/hSectionsScript.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
%% Section 2
66
a
7-
disp('This is second section')
7+
disp('This is second section')

src/test/tools/config/.mocharc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// Copyright 2024 The MathWorks, Inc.
1+
// Copyright 2024-2025 The MathWorks, Inc.
22
module.exports = {
33
timeout: 600000,
4-
ui: 'tdd'
4+
ui: 'tdd',
5+
retries: 1,
56
}

0 commit comments

Comments
 (0)