Skip to content

Commit 101448f

Browse files
dklilleyGitHub Enterprise
authored andcommitted
Merge pull request mathworks#44 from development/feature-section-highlighting
Feature section highlighting
2 parents 9764e68 + f341b6b commit 101448f

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

matlab/+matlabls/+internal/computeCodeData.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@
262262
end
263263

264264
catch exception
265-
disp(['Error occurred while fetching sections: ', exception.message]);
265+
disp(['Error occurred while fetching sections: ', exception.message]);
266+
% Add the error message to the codeInfo for syntax errors
267+
codeInfo.errorInfo = struct('message', exception.message);
266268
end
267269

268270
%% Finalize Data

src/indexing/FileInfoIndex.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export interface RawCodeData {
1212
packageName: string
1313
references: CodeDataReference[]
1414
sections: CodeDataSectionInfo[]
15+
errorInfo: CodeDataErrorInfo | undefined
16+
}
17+
18+
19+
interface CodeDataErrorInfo {
20+
message: string
1521
}
1622

1723
/**
@@ -373,16 +379,25 @@ export class MatlabCodeData {
373379
readonly references: Map<string, Range[]>
374380
readonly sections: Map<string, Range[]>
375381
readonly packageName: string
382+
errorMessage: string | undefined
376383

377384
constructor (public uri: string, rawCodeData: RawCodeData, public classInfo?: MatlabClassInfo) {
378385
this.functions = new Map<string, MatlabFunctionInfo>()
379386
this.references = new Map<string, Range[]>()
380387
this.sections = new Map<string, Range[]>()
381388
this.packageName = rawCodeData.packageName
382-
389+
this.errorMessage = undefined
383390
this.parseFunctions(rawCodeData.functionInfo)
384391
this.parseReferences(rawCodeData.references)
385392
this.parseSectionInfo(rawCodeData.sections)
393+
this.parseErrorInfo(rawCodeData.errorInfo)
394+
}
395+
parseErrorInfo (errorInfo: CodeDataErrorInfo | undefined) {
396+
if(errorInfo == undefined) {
397+
this.errorMessage = undefined
398+
return
399+
}
400+
this.errorMessage = errorInfo.message
386401
}
387402

388403
/**

src/notifications/NotificationService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export enum Notification {
3434
// Telemetry
3535
LogTelemetryData = 'telemetry/logdata',
3636

37+
// MATLAB File Sections Updates
38+
MatlabSections = 'matlab/sections',
39+
3740
// Licensing
3841
LicensingServerUrl = 'licensing/server/url',
3942
LicensingData = 'licensing/data',

src/providers/navigation/NavigationSupportProvider.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import MatlabLifecycleManager from '../../lifecycle/MatlabLifecycleManager'
1212
import Indexer from '../../indexing/Indexer'
1313
import DocumentIndexer from '../../indexing/DocumentIndexer'
1414
import PathResolver from './PathResolver'
15+
import NotificationService, { Notification } from '../../notifications/NotificationService'
1516

1617
class NavigationSupportProvider {
1718
constructor (
@@ -141,20 +142,31 @@ class NavigationSupportProvider {
141142
})
142143
})
143144

145+
144146
/**
145147
* Handle a case when the indexer fails due to the user being in the middle of an edit.
146148
* Here the documentSymbol cache has some symbols but the codeData cache has none. So we
147149
* assume that the user will soon fix their code and just fall back to what we knew for now.
148150
*/
149-
if (result.length === 0) {
151+
if (result.length === 0 && codeData.errorMessage !== undefined) {
150152
const cached = this._documentSymbolCache.get(uri) ?? result
151153
if (cached.length > 0) {
152154
return cached
153155
}
154156
}
155157
this._documentSymbolCache.set(uri, result)
158+
this._sendSectionRangesForHighlighting(result, uri)
156159
return result
157160
}
161+
162+
private _sendSectionRangesForHighlighting(result: SymbolInformation[], uri: string) {
163+
const sections = result.filter(result => result.kind === SymbolKind.Module)
164+
const sectionRanges: Range[] = []
165+
sections.forEach((section) => {
166+
sectionRanges.push(section.location.range)
167+
})
168+
NotificationService.sendNotification(Notification.MatlabSections, { uri, sectionRanges })
169+
}
158170
}
159171

160172
export default NavigationSupportProvider

0 commit comments

Comments
 (0)