-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1676
- Loading branch information
Showing
7 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; | ||
|
||
import sortByEndLineNumberAsc from './sortByEndLineNumberAsc'; | ||
|
||
export default function addMainContractCodeDecoration(model: monaco.editor.ITextModel, contractName: string, editor: monaco.editor.IStandaloneCodeEditor) { | ||
const options: monaco.editor.IModelDecorationOptions = { | ||
isWholeLine: true, | ||
}; | ||
|
||
const contractBlockMatches = model.findMatches(`^contract\\s`, false, true, false, null, true); | ||
|
||
if (contractBlockMatches.length < 2) { | ||
return; | ||
} | ||
|
||
const [ firstLineMatch ] = model.findMatches(`(^contract ${ contractName })( is .+)?\\s?\\{`, false, true, false, null, true); | ||
|
||
if (!firstLineMatch) { | ||
return; | ||
} | ||
|
||
const firstLineDecoration: monaco.editor.IModelDeltaDecoration = { | ||
range: { | ||
startColumn: 1, | ||
endColumn: 10, // doesn't really matter since isWholeLine is true | ||
startLineNumber: firstLineMatch.range.startLineNumber, | ||
endLineNumber: firstLineMatch.range.startLineNumber, | ||
}, | ||
options: { | ||
...options, | ||
className: '.main-contract-header', | ||
marginClassName: '.main-contract-header', | ||
glyphMarginClassName: '.main-contract-glyph', | ||
glyphMarginHoverMessage: [ | ||
{ value: 'Main contract' }, | ||
], | ||
}, | ||
}; | ||
|
||
const lastLineRange: monaco.IRange = { | ||
startLineNumber: firstLineMatch.range.startLineNumber, | ||
startColumn: 1, | ||
endColumn: 10, | ||
endLineNumber: model.getLineCount(), | ||
}; | ||
const [ lastLineMatch ] = model | ||
.findMatches(`^\\}`, lastLineRange, true, false, null, true) | ||
.sort(sortByEndLineNumberAsc); | ||
|
||
const restDecoration: monaco.editor.IModelDeltaDecoration = { | ||
range: { | ||
startLineNumber: firstLineMatch.range.startLineNumber + 1, | ||
endLineNumber: lastLineMatch.range.startLineNumber, | ||
startColumn: 1, | ||
endColumn: 10, // doesn't really matter since isWholeLine is true | ||
}, | ||
options: { | ||
...options, | ||
className: '.main-contract-body', | ||
marginClassName: '.main-contract-body', | ||
}, | ||
}; | ||
|
||
editor.updateOptions({ glyphMargin: true }); | ||
model.deltaDecorations([], [ firstLineDecoration, restDecoration ]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; | ||
|
||
export default function sortByEndLineNumberAsc(a: monaco.editor.FindMatch, b: monaco.editor.FindMatch) { | ||
if (a.range.endLineNumber < b.range.endLineNumber) { | ||
return -1; | ||
} | ||
|
||
if (a.range.endLineNumber > b.range.endLineNumber) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters