1717import * as vscode from 'vscode' ;
1818import { Messenger } from 'vscode-messenger' ;
1919import { WebviewIdMessageParticipant } from 'vscode-messenger-common' ;
20+ import { MemoryDisplaySettings , MemoryDisplaySettingsContribution , ScrollingBehavior } from '../common/memory-display-settings' ;
2021import { Endianness , VariableRange } from '../common/memory-range' ;
2122import {
2223 applyMemoryType ,
@@ -44,7 +45,7 @@ import {
4445 writeMemoryType ,
4546} from '../common/messaging' ;
4647import { getVisibleColumns , WebviewContext } from '../common/webview-context' ;
47- import { AddressPaddingOptions , MemoryViewSettings , ScrollingBehavior } from '../webview/utils/view-types' ;
48+ import { AddressPaddingOptions , MemoryViewSettings } from '../webview/utils/view-types' ;
4849import { isVariablesContext } from './external-views' ;
4950import { outputChannelLogger } from './logger' ;
5051import * as manifest from './manifest' ;
@@ -204,9 +205,9 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
204205 const participant = this . messenger . registerWebviewPanel ( panel ) ;
205206
206207 const disposables = [
207- this . messenger . onNotification ( readyType , ( ) => {
208- this . setInitialSettings ( participant , panel . title ) ;
208+ this . messenger . onNotification ( readyType , async ( ) => {
209209 this . setSessionContext ( participant , this . memoryProvider . createContext ( ) ) ;
210+ await this . setMemoryDisplaySettings ( participant , panel . title ) ;
210211 this . refresh ( participant , options ) ;
211212 } , { sender : participant } ) ,
212213 this . messenger . onRequest ( setOptionsType , o => {
@@ -216,7 +217,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
216217 this . messenger . onRequest ( readMemoryType , request => this . readMemory ( request ) , { sender : participant } ) ,
217218 this . messenger . onRequest ( writeMemoryType , request => this . writeMemory ( request ) , { sender : participant } ) ,
218219 this . messenger . onRequest ( getVariablesType , request => this . getVariables ( request ) , { sender : participant } ) ,
219- this . messenger . onNotification ( resetMemoryViewSettingsType , ( ) => this . setInitialSettings ( participant , panel . title ) , { sender : participant } ) ,
220+ this . messenger . onNotification ( resetMemoryViewSettingsType , ( ) => this . setMemoryDisplaySettings ( participant ) , { sender : participant } ) ,
220221 this . messenger . onNotification ( setTitleType , title => { panel . title = title ; } , { sender : participant } ) ,
221222 this . messenger . onRequest ( storeMemoryType , args => this . storeMemory ( args ) , { sender : participant } ) ,
222223 this . messenger . onRequest ( applyMemoryType , ( ) => this . applyMemory ( ) , { sender : participant } ) ,
@@ -237,39 +238,59 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
237238 panel . onDidDispose ( ( ) => disposables . forEach ( disposable => disposable . dispose ( ) ) ) ;
238239 }
239240
240- protected async refresh ( participant : WebviewIdMessageParticipant , options : MemoryOptions = { } ) : Promise < void > {
241- this . messenger . sendRequest ( setOptionsType , participant , options ) ;
241+ protected async setMemoryDisplaySettings ( participant : WebviewIdMessageParticipant , title ?: string ) : Promise < void > {
242+ const defaultSettings = this . getDefaultMemoryDisplaySettings ( ) ;
243+ const settingsContribution = await this . getSettingsContribution ( ) ;
244+ this . messenger . sendNotification ( setMemoryViewSettingsType , participant , {
245+ title,
246+ ...defaultSettings ,
247+ ...settingsContribution . settings ,
248+ contributionMessage : settingsContribution . message
249+ } ) ;
242250 }
243251
244- protected setInitialSettings ( webviewParticipant : WebviewIdMessageParticipant , title : string ) : void {
245- this . setMemoryViewSettings ( webviewParticipant , this . getMemoryViewSettings ( webviewParticipant , title ) ) ;
252+ protected async refresh ( participant : WebviewIdMessageParticipant , options : MemoryOptions = { } ) : Promise < void > {
253+ this . messenger . sendRequest ( setOptionsType , participant , options ) ;
246254 }
247255
248256 protected setMemoryViewSettings ( webviewParticipant : WebviewIdMessageParticipant , settings : Partial < MemoryViewSettings > ) : void {
249257 this . messenger . sendNotification ( setMemoryViewSettingsType , webviewParticipant , settings ) ;
250258 }
251259
260+ protected applyDisplaySettingContributions ( webviewParticipant : WebviewIdMessageParticipant , settingsContribution : Partial < MemoryDisplaySettingsContribution > ) : void {
261+ const { settings, message } = settingsContribution ;
262+ if ( settings && Object . keys ( settings ) . length ) {
263+ this . messenger . sendNotification ( setMemoryViewSettingsType , webviewParticipant , { ...settings , contributionMessage : message } ) ;
264+ }
265+ }
266+
252267 protected setSessionContext ( webviewParticipant : WebviewIdMessageParticipant , context : SessionContext ) : void {
253268 this . messenger . sendNotification ( sessionContextChangedType , webviewParticipant , context ) ;
254269 }
255270
256- protected getMemoryViewSettings ( messageParticipant : WebviewIdMessageParticipant , title : string ) : MemoryViewSettings {
257- const memoryInspectorConfiguration = vscode . workspace . getConfiguration ( manifest . PACKAGE_NAME ) ;
258- const bytesPerMau = memoryInspectorConfiguration . get < number > ( manifest . CONFIG_BYTES_PER_MAU , manifest . DEFAULT_BYTES_PER_MAU ) ;
259- const mausPerGroup = memoryInspectorConfiguration . get < number > ( manifest . CONFIG_MAUS_PER_GROUP , manifest . DEFAULT_MAUS_PER_GROUP ) ;
260- const groupsPerRow = memoryInspectorConfiguration . get < manifest . GroupsPerRowOption > ( manifest . CONFIG_GROUPS_PER_ROW , manifest . DEFAULT_GROUPS_PER_ROW ) ;
261- const endianness = memoryInspectorConfiguration . get < Endianness > ( manifest . CONFIG_ENDIANNESS , manifest . DEFAULT_ENDIANNESS ) ;
262- const scrollingBehavior = memoryInspectorConfiguration . get < ScrollingBehavior > ( manifest . CONFIG_SCROLLING_BEHAVIOR , manifest . DEFAULT_SCROLLING_BEHAVIOR ) ;
271+ protected getDefaultMemoryDisplaySettings ( ) : MemoryDisplaySettings {
272+ const memoryInspectorSettings = vscode . workspace . getConfiguration ( manifest . PACKAGE_NAME ) ;
273+ const bytesPerMau = memoryInspectorSettings . get < number > ( manifest . CONFIG_BYTES_PER_MAU , manifest . DEFAULT_BYTES_PER_MAU ) ;
274+ const mausPerGroup = memoryInspectorSettings . get < number > ( manifest . CONFIG_MAUS_PER_GROUP , manifest . DEFAULT_MAUS_PER_GROUP ) ;
275+ const groupsPerRow = memoryInspectorSettings . get < manifest . GroupsPerRowOption > ( manifest . CONFIG_GROUPS_PER_ROW , manifest . DEFAULT_GROUPS_PER_ROW ) ;
276+ const endianness = memoryInspectorSettings . get < Endianness > ( manifest . CONFIG_ENDIANNESS , manifest . DEFAULT_ENDIANNESS ) ;
277+ const scrollingBehavior = memoryInspectorSettings . get < ScrollingBehavior > ( manifest . CONFIG_SCROLLING_BEHAVIOR , manifest . DEFAULT_SCROLLING_BEHAVIOR ) ;
263278 const visibleColumns = CONFIGURABLE_COLUMNS
264- . filter ( column => vscode . workspace . getConfiguration ( manifest . PACKAGE_NAME ) . get < boolean > ( column , false ) )
279+ . filter ( column => memoryInspectorSettings . get < boolean > ( column , false ) )
265280 . map ( columnId => columnId . replace ( 'columns.' , '' ) ) ;
266- const addressPadding = AddressPaddingOptions [ memoryInspectorConfiguration . get ( manifest . CONFIG_ADDRESS_PADDING , manifest . DEFAULT_ADDRESS_PADDING ) ] ;
267- const addressRadix = memoryInspectorConfiguration . get < number > ( manifest . CONFIG_ADDRESS_RADIX , manifest . DEFAULT_ADDRESS_RADIX ) ;
268- const showRadixPrefix = memoryInspectorConfiguration . get < boolean > ( manifest . CONFIG_SHOW_RADIX_PREFIX , manifest . DEFAULT_SHOW_RADIX_PREFIX ) ;
269- return {
270- messageParticipant, title, bytesPerMau, mausPerGroup, groupsPerRow,
271- endianness, scrollingBehavior, visibleColumns, addressPadding, addressRadix, showRadixPrefix
272- } ;
281+ const addressPadding = AddressPaddingOptions [ memoryInspectorSettings . get ( manifest . CONFIG_ADDRESS_PADDING , manifest . DEFAULT_ADDRESS_PADDING ) ] ;
282+ const addressRadix = memoryInspectorSettings . get < number > ( manifest . CONFIG_ADDRESS_RADIX , manifest . DEFAULT_ADDRESS_RADIX ) ;
283+ const showRadixPrefix = memoryInspectorSettings . get < boolean > ( manifest . CONFIG_SHOW_RADIX_PREFIX , manifest . DEFAULT_SHOW_RADIX_PREFIX ) ;
284+ return { bytesPerMau, mausPerGroup, groupsPerRow, endianness, scrollingBehavior, visibleColumns, addressPadding, addressRadix, showRadixPrefix } ;
285+ }
286+
287+ protected async getSettingsContribution ( ) : Promise < MemoryDisplaySettingsContribution > {
288+ const memoryInspectorSettings = vscode . workspace . getConfiguration ( manifest . PACKAGE_NAME ) ;
289+ const allowSettingsExtension = memoryInspectorSettings . get < boolean > ( manifest . CONFIG_ALLOW_SETTINGS_EXTENSION , true ) ;
290+ if ( allowSettingsExtension ) {
291+ return this . memoryProvider . getMemoryDisplaySettingsContribution ( ) ;
292+ }
293+ return { settings : { } , message : '' } ;
273294 }
274295
275296 protected async readMemory ( request : ReadMemoryArguments ) : Promise < ReadMemoryResult > {
0 commit comments