Initial commit for Context Builder extension (#24094)

* Initial commit for context-builder extension

* Fix eslint unused param error
This commit is contained in:
Lewis Sanchez
2023-08-08 17:05:01 -07:00
committed by GitHub
parent 59fb8d6ddd
commit 606d808641
15 changed files with 1962 additions and 62 deletions

View File

@@ -35,14 +35,14 @@ function minifyExtensionResources(input) {
.pipe(jsonFilter) .pipe(jsonFilter)
.pipe(buffer()) .pipe(buffer())
.pipe(es.mapSync((f) => { .pipe(es.mapSync((f) => {
const errors = []; const errors = [];
const value = jsoncParser.parse(f.contents.toString('utf8'), errors, { allowTrailingComma: true }); const value = jsoncParser.parse(f.contents.toString('utf8'), errors, { allowTrailingComma: true });
if (errors.length === 0) { if (errors.length === 0) {
// file parsed OK => just stringify to drop whitespace and comments // file parsed OK => just stringify to drop whitespace and comments
f.contents = Buffer.from(JSON.stringify(value)); f.contents = Buffer.from(JSON.stringify(value));
} }
return f; return f;
})) }))
.pipe(jsonFilter.restore); .pipe(jsonFilter.restore);
} }
function updateExtensionPackageJSON(input, update) { function updateExtensionPackageJSON(input, update) {
@@ -51,10 +51,10 @@ function updateExtensionPackageJSON(input, update) {
.pipe(packageJsonFilter) .pipe(packageJsonFilter)
.pipe(buffer()) .pipe(buffer())
.pipe(es.mapSync((f) => { .pipe(es.mapSync((f) => {
const data = JSON.parse(f.contents.toString('utf8')); const data = JSON.parse(f.contents.toString('utf8'));
f.contents = Buffer.from(JSON.stringify(update(data))); f.contents = Buffer.from(JSON.stringify(update(data)));
return f; return f;
})) }))
.pipe(packageJsonFilter.restore); .pipe(packageJsonFilter.restore);
} }
function fromLocal(extensionPath, forWeb) { function fromLocal(extensionPath, forWeb) {
@@ -96,11 +96,11 @@ function fromLocalWebpack(extensionPath, webpackConfigFileName) {
const files = fileNames const files = fileNames
.map(fileName => path.join(extensionPath, fileName)) .map(fileName => path.join(extensionPath, fileName))
.map(filePath => new File({ .map(filePath => new File({
path: filePath, path: filePath,
stat: fs.statSync(filePath), stat: fs.statSync(filePath),
base: extensionPath, base: extensionPath,
contents: fs.createReadStream(filePath) contents: fs.createReadStream(filePath)
})); }));
// check for a webpack configuration files, then invoke webpack // check for a webpack configuration files, then invoke webpack
// and merge its output with the files stream. // and merge its output with the files stream.
const webpackConfigLocations = glob.sync(path.join(extensionPath, '**', webpackConfigFileName), { ignore: ['**/node_modules'] }); const webpackConfigLocations = glob.sync(path.join(extensionPath, '**', webpackConfigFileName), { ignore: ['**/node_modules'] });
@@ -127,20 +127,20 @@ function fromLocalWebpack(extensionPath, webpackConfigFileName) {
const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path); const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
return webpackGulp(webpackConfig, webpack, webpackDone) return webpackGulp(webpackConfig, webpack, webpackDone)
.pipe(es.through(function (data) { .pipe(es.through(function (data) {
data.stat = data.stat || {}; data.stat = data.stat || {};
data.base = extensionPath; data.base = extensionPath;
this.emit('data', data); this.emit('data', data);
})) }))
.pipe(es.through(function (data) { .pipe(es.through(function (data) {
// source map handling: // source map handling:
// * rewrite sourceMappingURL // * rewrite sourceMappingURL
// * save to disk so that upload-task picks this up // * save to disk so that upload-task picks this up
const contents = data.contents.toString('utf8'); const contents = data.contents.toString('utf8');
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) { data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`; return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
}), 'utf8'); }), 'utf8');
this.emit('data', data); this.emit('data', data);
})); }));
}); });
}); });
es.merge(...webpackStreams, es.readArray(files)) es.merge(...webpackStreams, es.readArray(files))
@@ -162,16 +162,16 @@ function fromLocalNormal(extensionPath) {
const result = es.through(); const result = es.through();
vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn }) vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn })
.then(fileNames => { .then(fileNames => {
const files = fileNames const files = fileNames
.map(fileName => path.join(extensionPath, fileName)) .map(fileName => path.join(extensionPath, fileName))
.map(filePath => new File({ .map(filePath => new File({
path: filePath, path: filePath,
stat: fs.statSync(filePath), stat: fs.statSync(filePath),
base: extensionPath, base: extensionPath,
contents: fs.createReadStream(filePath) contents: fs.createReadStream(filePath)
})); }));
es.readArray(files).pipe(result); es.readArray(files).pipe(result);
}) })
.catch(err => result.emit('error', err)); .catch(err => result.emit('error', err));
return result.pipe((0, stats_1.createStatsStream)(path.basename(extensionPath))); return result.pipe((0, stats_1.createStatsStream)(path.basename(extensionPath)));
} }
@@ -242,6 +242,7 @@ const externalExtensions = [
'azcli', 'azcli',
'azuremonitor', 'azuremonitor',
'cms', 'cms',
'context-builder',
'dacpac', 'dacpac',
'datavirtualization', 'datavirtualization',
'import', 'import',
@@ -306,11 +307,11 @@ function isWebExtension(manifest) {
function packageLocalExtensionsStream(forWeb) { function packageLocalExtensionsStream(forWeb) {
const localExtensionsDescriptions = (glob.sync('extensions/*/package.json') const localExtensionsDescriptions = (glob.sync('extensions/*/package.json')
.map(manifestPath => { .map(manifestPath => {
const absoluteManifestPath = path.join(root, manifestPath); const absoluteManifestPath = path.join(root, manifestPath);
const extensionPath = path.dirname(path.join(root, manifestPath)); const extensionPath = path.dirname(path.join(root, manifestPath));
const extensionName = path.basename(extensionPath); const extensionName = path.basename(extensionPath);
return { name: extensionName, path: extensionPath, manifestPath: absoluteManifestPath }; return { name: extensionName, path: extensionPath, manifestPath: absoluteManifestPath };
}) })
.filter(({ name }) => excludedExtensions.indexOf(name) === -1) .filter(({ name }) => excludedExtensions.indexOf(name) === -1)
.filter(({ name }) => builtInExtensions.every(b => b.name !== name)) .filter(({ name }) => builtInExtensions.every(b => b.name !== name))
.filter(({ name }) => externalExtensions.indexOf(name) === -1) // {{SQL CARBON EDIT}} Remove external Extensions with separate package .filter(({ name }) => externalExtensions.indexOf(name) === -1) // {{SQL CARBON EDIT}} Remove external Extensions with separate package
@@ -341,14 +342,14 @@ function packageMarketplaceExtensionsStream(forWeb) {
]; ];
const marketplaceExtensionsStream = minifyExtensionResources(es.merge(...marketplaceExtensionsDescriptions const marketplaceExtensionsStream = minifyExtensionResources(es.merge(...marketplaceExtensionsDescriptions
.map(extension => { .map(extension => {
const src = (0, builtInExtensions_1.getExtensionStream)(extension).pipe(rename(p => p.dirname = `extensions/${p.dirname}`)); const src = (0, builtInExtensions_1.getExtensionStream)(extension).pipe(rename(p => p.dirname = `extensions/${p.dirname}`));
return updateExtensionPackageJSON(src, (data) => { return updateExtensionPackageJSON(src, (data) => {
delete data.scripts; delete data.scripts;
delete data.dependencies; delete data.dependencies;
delete data.devDependencies; delete data.devDependencies;
return data; return data;
}); });
}))); })));
return (marketplaceExtensionsStream return (marketplaceExtensionsStream
.pipe(util2.setExecutableBit(['**/*.sh']))); .pipe(util2.setExecutableBit(['**/*.sh'])));
} }
@@ -393,10 +394,10 @@ exports.scanBuiltinExtensions = scanBuiltinExtensions;
function packageExternalExtensionsStream() { function packageExternalExtensionsStream() {
const extenalExtensionDescriptions = glob.sync('extensions/*/package.json') const extenalExtensionDescriptions = glob.sync('extensions/*/package.json')
.map(manifestPath => { .map(manifestPath => {
const extensionPath = path.dirname(path.join(root, manifestPath)); const extensionPath = path.dirname(path.join(root, manifestPath));
const extensionName = path.basename(extensionPath); const extensionName = path.basename(extensionPath);
return { name: extensionName, path: extensionPath }; return { name: extensionName, path: extensionPath };
}) })
.filter(({ name }) => externalExtensions.indexOf(name) >= 0 || exports.vscodeExternalExtensions.indexOf(name) >= 0); .filter(({ name }) => externalExtensions.indexOf(name) >= 0 || exports.vscodeExternalExtensions.indexOf(name) >= 0);
const builtExtensions = extenalExtensionDescriptions.map(extension => { const builtExtensions = extenalExtensionDescriptions.map(extension => {
return fromLocal(extension.path, false) return fromLocal(extension.path, false)
@@ -414,10 +415,10 @@ exports.cleanRebuildExtensions = cleanRebuildExtensions;
function packageRebuildExtensionsStream() { function packageRebuildExtensionsStream() {
const extenalExtensionDescriptions = glob.sync('extensions/*/package.json') const extenalExtensionDescriptions = glob.sync('extensions/*/package.json')
.map(manifestPath => { .map(manifestPath => {
const extensionPath = path.dirname(path.join(root, manifestPath)); const extensionPath = path.dirname(path.join(root, manifestPath));
const extensionName = path.basename(extensionPath); const extensionName = path.basename(extensionPath);
return { name: extensionName, path: extensionPath }; return { name: extensionName, path: extensionPath };
}) })
.filter(({ name }) => rebuildExtensions.indexOf(name) >= 0); .filter(({ name }) => rebuildExtensions.indexOf(name) >= 0);
const builtExtensions = extenalExtensionDescriptions.map(extension => { const builtExtensions = extenalExtensionDescriptions.map(extension => {
return fromLocal(extension.path, false) return fromLocal(extension.path, false)

View File

@@ -278,6 +278,7 @@ const externalExtensions = [
'azcli', 'azcli',
'azuremonitor', 'azuremonitor',
'cms', 'cms',
'context-builder',
'dacpac', 'dacpac',
'datavirtualization', 'datavirtualization',
'import', 'import',

View File

@@ -0,0 +1,13 @@
{
"parserOptions": {
"project": "./extensions/context-builder/tsconfig.json"
},
"rules": {
"@typescript-eslint/no-floating-promises": [
"error",
{
"ignoreVoid": true
}
]
}
}

1
extensions/context-builder/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.vsix

View File

@@ -0,0 +1,9 @@
src
out
tsconfig.json
.gitignore
coverage
coverConfig.json
extension.webpack.config.js
*.vsix
yarn.lock

View File

@@ -0,0 +1,19 @@
# Context Builder Extension for Azure Data Studio
## Overview
The Context Builder extension for Azure Data Studio assists with building context for the GitHub Copilot extension by maintaining a historical record of queries that have been executed. The tracked queries are provided to the GitHub Copilot extension, so that suggestions provided by Copilot are accurate and relevant to the current user's session.
## Privacy Statement
To learn more about our Privacy Statement visit [this link](https://go.microsoft.com/fwlink/?LinkID=824704).
## Feedback
Please report issues and feature requests [here.](https://github.com/microsoft/azuredatastudio/issues)
## License
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the [Source EULA](https://raw.githubusercontent.com/Microsoft/azuredatastudio/main/LICENSE.txt).

View File

@@ -0,0 +1,20 @@
{
"enabled": true,
"relativeSourcePath": "..",
"relativeCoverageDir": "../../coverage",
"ignorePatterns": [
"**/node_modules/**",
"**/test/**",
"extension.js"
],
"reports": [
"cobertura",
"lcov",
"json"
],
"verbose": false,
"remapOptions": {
"basePath": "..",
"useAbsolutePaths": true
}
}

View File

@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
'use strict';
const withDefaults = require('../shared.webpack.config');
module.exports = withDefaults({
context: __dirname,
entry: {
extension: './src/extension.ts'
}
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -0,0 +1,49 @@
{
"name": "context-builder",
"displayName": "%contextBuilder.displayName%",
"description": "%contextBuilder.description%",
"version": "0.1.0",
"publisher": "Microsoft",
"preview": true,
"engines": {
"vscode": "*",
"azdata": ">=1.45.0"
},
"license": "https://raw.githubusercontent.com/Microsoft/azuredatastudio/main/LICENSE.txt",
"icon": "images/extension.png",
"aiKey": "29a207bb14f84905966a8f22524cb730-25407f35-11b6-4d4e-8114-ab9e843cb52f-7380",
"activationEvents": [
"*"
],
"main": "./out/extension",
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/azuredatastudio.git"
},
"capabilities": {
"virtualWorkspaces": false,
"untrustedWorkspaces": {
"supported": true
}
},
"extensionDependencies": [
"Microsoft.mssql"
],
"contributes": {
"commands": [
],
"menus": {
"objectExplorer/item/context": [
],
"dataExplorer/context": [
],
"commandPalette": [
]
}
},
"dependencies": {
"vscode-nls": "^4.0.0"
},
"devDependencies": {
}
}

View File

@@ -0,0 +1,4 @@
{
"contextBuilder.displayName": "Context Builder",
"contextBuilder.description": "Context Builder extension for Azure Data Studio."
}

View File

@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//import * as vscode from 'vscode';
export async function activate(/*context: vscode.ExtensionContext*/): Promise<void> {
}
export function deactivate(): void {
}

View File

@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../../../src/vscode-dts/vscode.d.ts'/>
/// <reference path='../../../../src/sql/azdata.d.ts'/>
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
/// <reference path='../../../mssql/src/mssql.d.ts'/>
/// <reference types='@types/node'/>

View File

@@ -0,0 +1,15 @@
{
"extends": "../tsconfig.base.json",
"compileOnSave": true,
"compilerOptions": {
"outDir": "./out",
"lib": [
"es6",
"es2015.promise",
"dom"
]
},
"exclude": [
"node_modules"
]
}

File diff suppressed because it is too large Load Diff