-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Clean up non-visible diagnostics (#3867)
- Loading branch information
Showing
16 changed files
with
105 additions
and
60 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
print(foo.islower()) | ||
print(foo.isupper()) | ||
print(foo.isprintable()) | ||
|
||
# Stop the execution of the script |
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
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 |
---|---|---|
@@ -1,47 +1,8 @@ | ||
import type { Uri } from 'vscode'; | ||
import { window } from 'vscode'; | ||
|
||
import { createIsUriVisibleFilter } from '../vscode/createIsUriVisibleFilter.mjs'; | ||
|
||
export function createIsItemVisibleFilter<T extends { uri: Uri }>(onlyVisible: boolean): (item: T) => boolean { | ||
const filter = createIsUriVisibleFilter(onlyVisible); | ||
return (item: T) => filter(item.uri); | ||
} | ||
|
||
export function createIsUriVisibleFilter(onlyVisible: boolean): (uri: Uri) => boolean { | ||
if (!onlyVisible) return () => true; | ||
// Use the path to avoid scheme issues. | ||
const tabs = extractUrisFromTabs(); | ||
|
||
const visibleUris = new Set([ | ||
...tabs.map((tab) => tab.uri.toString()), | ||
...window.visibleTextEditors.map((e) => e.document.uri.toString()), | ||
]); | ||
return (uri: Uri) => { | ||
const h = visibleUris.has(uri.toString()); | ||
// console.log('isUriVisible', uri.toString(), h); | ||
return h; | ||
}; | ||
} | ||
|
||
interface TabUri { | ||
label: string; | ||
uri: Uri; | ||
} | ||
|
||
function extractUrisFromTabs(): TabUri[] { | ||
const tabs: TabUri[] = []; | ||
|
||
for (const tg of window.tabGroups.all) { | ||
for (const tab of tg.tabs) { | ||
const { label, input } = tab; | ||
if (hasUri(input)) { | ||
tabs.push({ label, uri: input.uri }); | ||
} | ||
} | ||
} | ||
return tabs; | ||
} | ||
|
||
function hasUri<T extends { uri: Uri }>(v: T | unknown): v is T { | ||
if (!v || typeof v !== 'object') return false; | ||
return 'uri' in v; | ||
} |
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
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,19 @@ | ||
import { type Uri, window } from 'vscode'; | ||
|
||
import { findTabsWithUriInput } from './tabs.mjs'; | ||
|
||
export function createIsUriVisibleFilter(onlyVisible: boolean): (uri: Uri) => boolean { | ||
if (!onlyVisible) return () => true; | ||
// Use the path to avoid scheme issues. | ||
const tabs = findTabsWithUriInput(); | ||
|
||
const visibleUris = new Set([ | ||
...tabs.map((tab) => tab.uri.toString()), | ||
...window.visibleTextEditors.map((e) => e.document.uri.toString()), | ||
]); | ||
return (uri: Uri) => { | ||
const h = visibleUris.has(uri.toString()); | ||
// console.log('isUriVisible', uri.toString(), h); | ||
return h; | ||
}; | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/client/src/util/findEditor.ts → packages/client/src/vscode/findEditor.ts
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,8 @@ | ||
import { Uri } from 'vscode'; | ||
|
||
interface UriResource { | ||
readonly uri: Uri; | ||
} | ||
export function isUriResource<T extends UriResource>(r: unknown | undefined): r is T { | ||
return r instanceof Object && 'uri' in r && r.uri instanceof Uri; | ||
} |
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,39 @@ | ||
import type { Tab, Uri } from 'vscode'; | ||
import { window } from 'vscode'; | ||
|
||
import { isUriResource } from './isUriResource.mjs'; | ||
|
||
interface TabUri { | ||
label: string; | ||
uri: Uri; | ||
tab: Tab; | ||
} | ||
export function findTabsWithUriInput(): TabUri[] { | ||
const tabs: TabUri[] = []; | ||
|
||
for (const tg of window.tabGroups.all) { | ||
for (const tab of tg.tabs) { | ||
const { label, input } = tab; | ||
if (hasUri(input)) { | ||
tabs.push({ tab, label, uri: input.uri }); | ||
} | ||
} | ||
} | ||
return tabs; | ||
} | ||
function hasUri<T extends { uri: Uri }>(v: T | unknown): v is T { | ||
if (!v || typeof v !== 'object') return false; | ||
return 'uri' in v; | ||
} | ||
|
||
export function extractUrisFromTabs(): Uri[] { | ||
return window.tabGroups.all | ||
.flatMap((tabGroup) => tabGroup.tabs) | ||
.map((tab) => tab.input) | ||
.filter(isUriResource) | ||
.map((r) => r.uri); | ||
} | ||
|
||
export function findAllOpenUrisInTabs(): Uri[] { | ||
return extractUrisFromTabs(); | ||
} |
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