Skip to content

Commit c7e5922

Browse files
committed
Merge branch 'main' into starcke/language-context-store
2 parents bb25874 + d5c78fd commit c7e5922

File tree

20 files changed

+685
-243
lines changed

20 files changed

+685
-243
lines changed

extensions/ql-vscode/package.json

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -757,38 +757,74 @@
757757
"command": "codeQLDatabases.displayAllLanguages",
758758
"title": "All languages"
759759
},
760+
{
761+
"command": "codeQLDatabases.displayAllLanguagesSelected",
762+
"title": "All languages (selected)"
763+
},
760764
{
761765
"command": "codeQLDatabases.displayCpp",
762766
"title": "C/C++"
763767
},
768+
{
769+
"command": "codeQLDatabases.displayCppSelected",
770+
"title": "C/C++ (selected)"
771+
},
764772
{
765773
"command": "codeQLDatabases.displayCsharp",
766774
"title": "C#"
767775
},
776+
{
777+
"command": "codeQLDatabases.displayCsharpSelected",
778+
"title": "C# (selected)"
779+
},
768780
{
769781
"command": "codeQLDatabases.displayGo",
770782
"title": "Go"
771783
},
784+
{
785+
"command": "codeQLDatabases.displayGoSelected",
786+
"title": "Go (selected)"
787+
},
772788
{
773789
"command": "codeQLDatabases.displayJava",
774790
"title": "Java/Kotlin"
775791
},
792+
{
793+
"command": "codeQLDatabases.displayJavaSelected",
794+
"title": "Java/Kotlin (selected)"
795+
},
776796
{
777797
"command": "codeQLDatabases.displayJavascript",
778798
"title": "JavaScript/TypeScript"
779799
},
800+
{
801+
"command": "codeQLDatabases.displayJavascriptSelected",
802+
"title": "JavaScript/TypeScript (selected)"
803+
},
780804
{
781805
"command": "codeQLDatabases.displayPython",
782806
"title": "Python"
783807
},
808+
{
809+
"command": "codeQLDatabases.displayPythonSelected",
810+
"title": "Python (selected)"
811+
},
784812
{
785813
"command": "codeQLDatabases.displayRuby",
786814
"title": "Ruby"
787815
},
816+
{
817+
"command": "codeQLDatabases.displayRubySelected",
818+
"title": "Ruby (selected)"
819+
},
788820
{
789821
"command": "codeQLDatabases.displaySwift",
790822
"title": "Swift"
791823
},
824+
{
825+
"command": "codeQLDatabases.displaySwiftSelected",
826+
"title": "Swift (selected)"
827+
},
792828
{
793829
"command": "codeQL.chooseDatabaseFolder",
794830
"title": "CodeQL: Choose Database from Folder"
@@ -1568,38 +1604,74 @@
15681604
"command": "codeQLDatabases.displayAllLanguages",
15691605
"when": "false"
15701606
},
1607+
{
1608+
"command": "codeQLDatabases.displayAllLanguagesSelected",
1609+
"when": "false"
1610+
},
15711611
{
15721612
"command": "codeQLDatabases.displayCpp",
15731613
"when": "false"
15741614
},
1615+
{
1616+
"command": "codeQLDatabases.displayCppSelected",
1617+
"when": "false"
1618+
},
15751619
{
15761620
"command": "codeQLDatabases.displayCsharp",
15771621
"when": "false"
15781622
},
1623+
{
1624+
"command": "codeQLDatabases.displayCsharpSelected",
1625+
"when": "false"
1626+
},
15791627
{
15801628
"command": "codeQLDatabases.displayGo",
15811629
"when": "false"
15821630
},
1631+
{
1632+
"command": "codeQLDatabases.displayGoSelected",
1633+
"when": "false"
1634+
},
15831635
{
15841636
"command": "codeQLDatabases.displayJava",
15851637
"when": "false"
15861638
},
1639+
{
1640+
"command": "codeQLDatabases.displayJavaSelected",
1641+
"when": "false"
1642+
},
15871643
{
15881644
"command": "codeQLDatabases.displayJavascript",
15891645
"when": "false"
15901646
},
1647+
{
1648+
"command": "codeQLDatabases.displayJavascriptSelected",
1649+
"when": "false"
1650+
},
15911651
{
15921652
"command": "codeQLDatabases.displayPython",
15931653
"when": "false"
15941654
},
1655+
{
1656+
"command": "codeQLDatabases.displayPythonSelected",
1657+
"when": "false"
1658+
},
15951659
{
15961660
"command": "codeQLDatabases.displayRuby",
15971661
"when": "false"
15981662
},
1663+
{
1664+
"command": "codeQLDatabases.displayRubySelected",
1665+
"when": "false"
1666+
},
15991667
{
16001668
"command": "codeQLDatabases.displaySwift",
16011669
"when": "false"
16021670
},
1671+
{
1672+
"command": "codeQLDatabases.displaySwiftSelected",
1673+
"when": "false"
1674+
},
16031675
{
16041676
"command": "codeQLQueryHistory.openQueryContextMenu",
16051677
"when": "false"
@@ -1797,31 +1869,76 @@
17971869
],
17981870
"codeQLDatabases.languages": [
17991871
{
1800-
"command": "codeQLDatabases.displayAllLanguages"
1872+
"command": "codeQLDatabases.displayAllLanguages",
1873+
"when": "codeQLDatabases.languageFilter != All"
1874+
},
1875+
{
1876+
"command": "codeQLDatabases.displayAllLanguagesSelected",
1877+
"when": "codeQLDatabases.languageFilter == All"
1878+
},
1879+
{
1880+
"command": "codeQLDatabases.displayCpp",
1881+
"when": "codeQLDatabases.languageFilter != cpp"
1882+
},
1883+
{
1884+
"command": "codeQLDatabases.displayCppSelected",
1885+
"when": "codeQLDatabases.languageFilter == cpp"
1886+
},
1887+
{
1888+
"command": "codeQLDatabases.displayCsharp",
1889+
"when": "codeQLDatabases.languageFilter != csharp"
1890+
},
1891+
{
1892+
"command": "codeQLDatabases.displayCsharpSelected",
1893+
"when": "codeQLDatabases.languageFilter == csharp"
1894+
},
1895+
{
1896+
"command": "codeQLDatabases.displayGo",
1897+
"when": "codeQLDatabases.languageFilter != go"
1898+
},
1899+
{
1900+
"command": "codeQLDatabases.displayGoSelected",
1901+
"when": "codeQLDatabases.languageFilter == go"
18011902
},
18021903
{
1803-
"command": "codeQLDatabases.displayCpp"
1904+
"command": "codeQLDatabases.displayJava",
1905+
"when": "codeQLDatabases.languageFilter != java"
18041906
},
18051907
{
1806-
"command": "codeQLDatabases.displayCsharp"
1908+
"command": "codeQLDatabases.displayJavaSelected",
1909+
"when": "codeQLDatabases.languageFilter == java"
18071910
},
18081911
{
1809-
"command": "codeQLDatabases.displayGo"
1912+
"command": "codeQLDatabases.displayJavascript",
1913+
"when": "codeQLDatabases.languageFilter != javascript"
18101914
},
18111915
{
1812-
"command": "codeQLDatabases.displayJava"
1916+
"command": "codeQLDatabases.displayJavascriptSelected",
1917+
"when": "codeQLDatabases.languageFilter == javascript"
18131918
},
18141919
{
1815-
"command": "codeQLDatabases.displayJavascript"
1920+
"command": "codeQLDatabases.displayPython",
1921+
"when": "codeQLDatabases.languageFilter != python"
18161922
},
18171923
{
1818-
"command": "codeQLDatabases.displayPython"
1924+
"command": "codeQLDatabases.displayPythonSelected",
1925+
"when": "codeQLDatabases.languageFilter == python"
18191926
},
18201927
{
1821-
"command": "codeQLDatabases.displayRuby"
1928+
"command": "codeQLDatabases.displayRuby",
1929+
"when": "codeQLDatabases.languageFilter != ruby"
1930+
},
1931+
{
1932+
"command": "codeQLDatabases.displayRubySelected",
1933+
"when": "codeQLDatabases.languageFilter == ruby"
1934+
},
1935+
{
1936+
"command": "codeQLDatabases.displaySwift",
1937+
"when": "codeQLDatabases.languageFilter != swift"
18221938
},
18231939
{
1824-
"command": "codeQLDatabases.displaySwift"
1940+
"command": "codeQLDatabases.displaySwiftSelected",
1941+
"when": "codeQLDatabases.languageFilter == swift"
18251942
}
18261943
]
18271944
},

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { dirname, join, delimiter } from "path";
66
import * as sarif from "sarif";
77
import { SemVer } from "semver";
88
import { Readable } from "stream";
9-
import { StringDecoder } from "string_decoder";
109
import tk from "tree-kill";
1110
import { promisify } from "util";
1211
import { CancellationToken, Disposable, Uri } from "vscode";
@@ -31,6 +30,7 @@ import { CompilationMessage } from "../query-server/legacy-messages";
3130
import { sarifParser } from "../common/sarif-parser";
3231
import { App } from "../common/app";
3332
import { QueryLanguage } from "../common/query-language";
33+
import { LINE_ENDINGS, splitStreamAtSeparators } from "../common/split-stream";
3434

3535
/**
3636
* The version of the SARIF format that we are using.
@@ -1649,120 +1649,13 @@ export async function runCodeQlCliCommand(
16491649
}
16501650
}
16511651

1652-
/**
1653-
* Buffer to hold state used when splitting a text stream into lines.
1654-
*/
1655-
class SplitBuffer {
1656-
private readonly decoder = new StringDecoder("utf8");
1657-
private readonly maxSeparatorLength: number;
1658-
private buffer = "";
1659-
private searchIndex = 0;
1660-
1661-
constructor(private readonly separators: readonly string[]) {
1662-
this.maxSeparatorLength = separators
1663-
.map((s) => s.length)
1664-
.reduce((a, b) => Math.max(a, b), 0);
1665-
}
1666-
1667-
/**
1668-
* Append new text data to the buffer.
1669-
* @param chunk The chunk of data to append.
1670-
*/
1671-
public addChunk(chunk: Buffer): void {
1672-
this.buffer += this.decoder.write(chunk);
1673-
}
1674-
1675-
/**
1676-
* Signal that the end of the input stream has been reached.
1677-
*/
1678-
public end(): void {
1679-
this.buffer += this.decoder.end();
1680-
this.buffer += this.separators[0]; // Append a separator to the end to ensure the last line is returned.
1681-
}
1682-
1683-
/**
1684-
* A version of startsWith that isn't overriden by a broken version of ms-python.
1685-
*
1686-
* The definition comes from
1687-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
1688-
* which is CC0/public domain
1689-
*
1690-
* See https://github.com/github/vscode-codeql/issues/802 for more context as to why we need it.
1691-
*/
1692-
private static startsWith(
1693-
s: string,
1694-
searchString: string,
1695-
position: number,
1696-
): boolean {
1697-
const pos = position > 0 ? position | 0 : 0;
1698-
return s.substring(pos, pos + searchString.length) === searchString;
1699-
}
1700-
1701-
/**
1702-
* Extract the next full line from the buffer, if one is available.
1703-
* @returns The text of the next available full line (without the separator), or `undefined` if no
1704-
* line is available.
1705-
*/
1706-
public getNextLine(): string | undefined {
1707-
while (this.searchIndex <= this.buffer.length - this.maxSeparatorLength) {
1708-
for (const separator of this.separators) {
1709-
if (SplitBuffer.startsWith(this.buffer, separator, this.searchIndex)) {
1710-
const line = this.buffer.slice(0, this.searchIndex);
1711-
this.buffer = this.buffer.slice(this.searchIndex + separator.length);
1712-
this.searchIndex = 0;
1713-
return line;
1714-
}
1715-
}
1716-
this.searchIndex++;
1717-
}
1718-
1719-
return undefined;
1720-
}
1721-
}
1722-
1723-
/**
1724-
* Splits a text stream into lines based on a list of valid line separators.
1725-
* @param stream The text stream to split. This stream will be fully consumed.
1726-
* @param separators The list of strings that act as line separators.
1727-
* @returns A sequence of lines (not including separators).
1728-
*/
1729-
async function* splitStreamAtSeparators(
1730-
stream: Readable,
1731-
separators: string[],
1732-
): AsyncGenerator<string, void, unknown> {
1733-
const buffer = new SplitBuffer(separators);
1734-
for await (const chunk of stream) {
1735-
buffer.addChunk(chunk);
1736-
let line: string | undefined;
1737-
do {
1738-
line = buffer.getNextLine();
1739-
if (line !== undefined) {
1740-
yield line;
1741-
}
1742-
} while (line !== undefined);
1743-
}
1744-
buffer.end();
1745-
let line: string | undefined;
1746-
do {
1747-
line = buffer.getNextLine();
1748-
if (line !== undefined) {
1749-
yield line;
1750-
}
1751-
} while (line !== undefined);
1752-
}
1753-
1754-
/**
1755-
* Standard line endings for splitting human-readable text.
1756-
*/
1757-
const lineEndings = ["\r\n", "\r", "\n"];
1758-
17591652
/**
17601653
* Log a text stream to a `Logger` interface.
17611654
* @param stream The stream to log.
17621655
* @param logger The logger that will consume the stream output.
17631656
*/
17641657
async function logStream(stream: Readable, logger: BaseLogger): Promise<void> {
1765-
for await (const line of splitStreamAtSeparators(stream, lineEndings)) {
1658+
for await (const line of splitStreamAtSeparators(stream, LINE_ENDINGS)) {
17661659
// Await the result of log here in order to ensure the logs are written in the correct order.
17671660
await logger.log(line);
17681661
}

extensions/ql-vscode/src/common/commands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ export type LocalDatabasesCommands = {
228228
"codeQLDatabases.displayPython": () => Promise<void>;
229229
"codeQLDatabases.displayRuby": () => Promise<void>;
230230
"codeQLDatabases.displaySwift": () => Promise<void>;
231+
"codeQLDatabases.displayAllLanguagesSelected": () => Promise<void>;
232+
"codeQLDatabases.displayCppSelected": () => Promise<void>;
233+
"codeQLDatabases.displayCsharpSelected": () => Promise<void>;
234+
"codeQLDatabases.displayGoSelected": () => Promise<void>;
235+
"codeQLDatabases.displayJavaSelected": () => Promise<void>;
236+
"codeQLDatabases.displayJavascriptSelected": () => Promise<void>;
237+
"codeQLDatabases.displayPythonSelected": () => Promise<void>;
238+
"codeQLDatabases.displayRubySelected": () => Promise<void>;
239+
"codeQLDatabases.displaySwiftSelected": () => Promise<void>;
231240

232241
// Database panel context menu
233242
"codeQLDatabases.setCurrentDatabase": (

0 commit comments

Comments
 (0)