Skip to content

Commit

Permalink
Merge pull request #3592 from ryanbrandenburg/rybrande/VirtualFiles
Browse files Browse the repository at this point in the history
Ignore virtual files
  • Loading branch information
JoeRobich authored Feb 25, 2020
2 parents 1ebb473 + e78397c commit ce7433c
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
obj
node_modules
out
.omnisharp/
Expand Down
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@
],
"preLaunchTask": "buildDev"
},
{
"name": "Launch razorcsproj Workspace Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1",
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
],
"env": {
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1",
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
"OSVC_SUITE": "BasicRazorApp2_1"
},
},
{
"name": "Launch slnWithCsproj Workspace Tests",
"type": "extensionHost",
Expand Down
6 changes: 6 additions & 0 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ class DiagnosticsProvider extends AbstractSupport {
return;
}

// No problems published for virtual files
if(isVirtualCSharpDocument(document))
{
return;
}

// (re)set new diagnostics for this document
let diagnosticsInFile = this._mapQuickFixesAsDiagnosticsInFile(quickFixes);

Expand Down
7 changes: 6 additions & 1 deletion tasks/testTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ gulp.task("test:integration:slnWithCsproj", async () => {
return runIntegrationTest("slnWithCsproj");
});

gulp.task("test:integration:BasicRazorApp2_1", async () => {
return runIntegrationTest("BasicRazorApp2_1");
});

gulp.task(
"test:integration", gulp.series(
"test:integration:singleCsproj",
"test:integration:slnWithCsproj"
"test:integration:slnWithCsproj",
"test:integration:BasicRazorApp2_1"
));

gulp.task("test", gulp.series(
Expand Down
7 changes: 6 additions & 1 deletion test/integrationTests/advisor.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';

import { expect } from 'chai';
import * as path from 'path';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';

import { Advisor } from '../../src/features/diagnosticsProvider';
Expand All @@ -25,6 +25,11 @@ suite(`Advisor ${testAssetWorkspace.description}`, function () {
let advisor: Advisor;

suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

let activationResult = await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
8 changes: 7 additions & 1 deletion test/integrationTests/codeActionRename.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as vscode from 'vscode';

import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import * as path from 'path';
import { assertWithPoll } from './poll';
Expand All @@ -20,6 +20,12 @@ suite(`Code Action Rename ${testAssetWorkspace.description}`, function () {

suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import * as vscode from 'vscode';
import testAssetWorkspace from "./testAssets/testAssetWorkspace";
import * as path from "path";
import { expect } from "chai";
import { activateCSharpExtension } from "./integrationHelpers";
import { activateCSharpExtension, isRazorWorkspace } from "./integrationHelpers";

suite(`${OmniSharpCompletionItemProvider.name}: Returns the completion items`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function() {
// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
9 changes: 7 additions & 2 deletions test/integrationTests/definitionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import CSharpDefinitionProvider from "../../src/features/definitionProvider";
import * as path from "path";
import testAssetWorkspace from "./testAssets/testAssetWorkspace";
import { expect } from "chai";
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';

suite(`${CSharpDefinitionProvider.name}: ${testAssetWorkspace.description}`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
57 changes: 55 additions & 2 deletions test/integrationTests/diagnostics.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import * as vscode from 'vscode';
import * as path from 'path';

import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { poll, assertWithPoll } from './poll';
import { poll, assertWithPoll, pollDoesNotHappen } from './poll';

const chai = require('chai');
chai.use(require('chai-arrays'));
Expand All @@ -23,6 +23,8 @@ function setDiagnosticWorkspaceLimit(to: number | null) {
suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () {
let fileUri: vscode.Uri;
let secondaryFileUri: vscode.Uri;
let razorFileUri: vscode.Uri;
let virtualRazorFileUri: vscode.Uri;

suiteSetup(async function () {
should();
Expand All @@ -36,11 +38,56 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () {

fileUri = vscode.Uri.file(path.join(projectDirectory, fileName));
secondaryFileUri = vscode.Uri.file(path.join(projectDirectory, secondaryFileName));
razorFileUri = vscode.Uri.file(path.join(projectDirectory, 'Pages', 'ErrorHaver.razor'));
virtualRazorFileUri = vscode.Uri.file(razorFileUri.fsPath + '__virtual.cs');
});

suite("razor workspace", () => {
suiteSetup(async function () {
should();

// These tests only run on the BasicRazorApp2_1 solution
if (!isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();
await vscode.commands.executeCommand("vscode.open", razorFileUri);
});

test("Razor shouldn't give diagnostics for virtual files", async () => {
await pollDoesNotHappen(() => vscode.languages.getDiagnostics(), 5 * 1000, 500, function(res) {
const virtual = res.find(r => r[0].fsPath === virtualRazorFileUri.fsPath);

if(!virtual) {
return false;
}

const diagnosticsList = virtual[1];
if(diagnosticsList.some(diag => diag.code == 'CS0103')) {
return true;
}
else{
return false;
}
});
});

suiteTeardown(async () => {
await testAssetWorkspace.cleanupWorkspace();
});
});

suite("small workspace (based on maxProjectFileCountForDiagnosticAnalysis setting)", () => {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();
await vscode.commands.executeCommand("vscode.open", fileUri);
Expand Down Expand Up @@ -78,6 +125,12 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () {
suite("large workspace (based on maxProjectFileCountForDiagnosticAnalysis setting)", () => {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await setDiagnosticWorkspaceLimit(1);
await testAssetWorkspace.restore();
await activateCSharpExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as path from 'path';

import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';

const chai = require('chai');
Expand All @@ -19,6 +19,12 @@ suite(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, function () {

suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
8 changes: 7 additions & 1 deletion test/integrationTests/hoverProvider.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as path from 'path';

import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';

const chai = require('chai');
Expand All @@ -17,6 +17,12 @@ chai.use(require('chai-fs'));
suite(`Hover Provider: ${testAssetWorkspace.description}`, function () {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();
});
Expand Down
9 changes: 7 additions & 2 deletions test/integrationTests/implementationProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import CSharpImplementationProvider from "../../src/features/implementationProvi
import * as path from "path";
import testAssetWorkspace from "./testAssets/testAssetWorkspace";
import { expect } from "chai";
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';

suite(`${CSharpImplementationProvider.name}: ${testAssetWorkspace.description}`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function() {
// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
6 changes: 6 additions & 0 deletions test/integrationTests/integrationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as path from 'path';
import * as vscode from 'vscode';
import CSharpExtensionExports from '../../src/CSharpExtensionExports';
import { Advisor } from '../../src/features/diagnosticsProvider';
Expand Down Expand Up @@ -34,4 +35,9 @@ export async function activateCSharpExtension(): Promise<ActivationResult | unde
}
}

export function isRazorWorkspace(workspace: typeof vscode.workspace) {
const primeWorkspace = workspace.workspaceFolders[0];
const projectFileName = primeWorkspace.uri.fsPath.split(path.sep).pop();

return projectFileName === 'BasicRazorApp2_1';
}
13 changes: 9 additions & 4 deletions test/integrationTests/languageMiddleware.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import * as vscode from "vscode";
import * as path from "path";
import testAssetWorkspace from "./testAssets/testAssetWorkspace";
import { expect } from "chai";
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import { LanguageMiddleware, LanguageMiddlewareFeature } from "../../src/omnisharp/LanguageMiddlewareFeature";

suite(`${LanguageMiddlewareFeature.name}: ${testAssetWorkspace.description}`, () => {
let fileUri: vscode.Uri;
let remappedFileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await registerLanguageMiddleware();
await testAssetWorkspace.restore();
Expand All @@ -41,7 +46,7 @@ suite(`${LanguageMiddlewareFeature.name}: ${testAssetWorkspace.description}`, ()
fileUri,
new vscode.Position(4, 30),
'newName'));

let entries = workspaceEdit!.entries();
expect(entries.length).to.be.equal(1);
expect(entries[0][0].path).to.be.equal(remappedFileUri.path);
Expand Down Expand Up @@ -93,7 +98,7 @@ class TestLanguageMiddleware implements LanguageMiddleware
let fileToRemap = 'remap.cs';
this.fileToRemapUri = vscode.Uri.file(path.join(projectDirectory, fileToRemap));
}

remapWorkspaceEdit?(workspaceEdit: vscode.WorkspaceEdit, token: vscode.CancellationToken): vscode.ProviderResult<vscode.WorkspaceEdit> {
const newEdit = new vscode.WorkspaceEdit();
for (const entry of workspaceEdit.entries()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fs from 'async-file';
import * as vscode from 'vscode';

import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { poll } from './poll';

Expand All @@ -18,6 +18,12 @@ chai.use(require('chai-fs'));
suite(`Tasks generation: ${testAssetWorkspace.description}`, function () {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (isRazorWorkspace(vscode.workspace)) {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
Loading

0 comments on commit ce7433c

Please sign in to comment.