New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vo/active window changes #15
Conversation
src/datadog-metrics.ts
Outdated
filter((editor): editor is sourcegraph.CodeEditor => editor !== undefined) | ||
) | ||
|
||
// When the configuration or current file changes, publish new decorations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// When the configuration or current file changes, publish new decorations. | |
// When the active editor changes, publish new decorations. |
src/datadog-metrics.ts
Outdated
editor.setDecorations(decorationType, decorations) | ||
}) | ||
) | ||
} | ||
} | ||
} | ||
sourcegraph.workspace.onDidOpenTextDocument.subscribe(() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You won't be needing this anymore.
src/datadog-metrics.ts
Outdated
const decorationType = sourcegraph.app.createDecorationType() | ||
setTimeout(() => editor.setDecorations(decorationType, decorations), 200) | ||
|
||
if (sourcegraph.app.activeWindowChanges) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block looks fine, but it should not be contained in the body decorateEditors()
. decorateEditors()
is also probably useless now. You probably want something like this:
function decorateEditor(editor: sourcegraph.CodeEditor): void {
// decoration logic goes here
}
export function activate(context: sourcegraph.extension.Context): void {
// declare `activeEditor` above
context.subscriptions.add(
activeEditor.subscribe(decorateEditor)
)
}
src/datadog-metrics.ts
Outdated
STATSD_PATTERN.lastIndex = 0 // reset | ||
function decorateEditor(editor: sourcegraph.CodeEditor): void { | ||
const decorations: sourcegraph.TextDocumentDecoration[] = [] | ||
const decorationType = sourcegraph.app.createDecorationType() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to create the decorationType
at the top level, otherwise you may get duplicate decorations.
const decorationType = sourcegraph.app.createDecorationType() | ||
for (const [i, line] of editor.document.text!.split('\n').entries()) { | ||
let m: RegExpExecArray | null | ||
do { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This do {} while {}
feels very unidiomatic. Why do you need it? Can't you simply do the following:
const match = line.match(STATSD_PATTERN)
if (match) {
// stuff
}
(string.match(regex)
returns all matches of a global regExp as an array)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, even if you're working on the assumption that there are several matches per line, the decorations you add on the same line will be indistinguishable from each other (they will all read ' View metric (Datadog) » '
)
src/datadog-metrics.ts
Outdated
} | ||
|
||
export function activate(context: sourcegraph.ExtensionContext): void { | ||
const activeEditor = from(sourcegraph.app.activeWindowChanges).pipe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw if sourcegraph.app.activeWindowChanges
is undefined (which, again, will only happen on < 3.1 instances). Move it into the if
block below.
WIP: Use activeWindowChanges to keep track changes and ensure window accessibility.